##单调队列做法,只有30分
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
const int N = 3e6 + 10;
int n, k;
int a[N];
deque <int> q;
int res;
int main() {
cin >> k >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
for (int i = 1; i <= n; i ++) {
while (!q.empty() && a[q.back()] > a[i]) {
q.pop_back();
}
q.push_back(i);
if (q.size() > 1 && a[q.back()] - a[q.front()] <= k) {
res = max(res, q.back() - q.front() + 1);
}
while (q.size() > 1 && a[q.back()] - a[q.front()] > k) {
q.pop_front();
}
}
cout << res << endl;
return 0;
}