#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, k, w, tmp, pos;
int A[200005], B[200005], bits[200005];
pair<int, int> p[200005];
int a, b;
void update(int k) {
  for (int i = k; i <= n; i += (i & -i)) bits[i]++;
}
int query(int l, int r) {
  if (r < l) return 0;
  int ret = 0;
  for (int i = r; i > 0; i -= (i & -i)) ret += bits[i];
  for (int i = l - 1; i > 0; i -= (i & -i)) ret -= bits[i];
  return ret;
}
int ans;
void solve(int l, int r) {
  for (int i = (l); i <= (r); i++) {
    k = p[i].second;
    if (A[k] >= m) continue;
    pos = min(n, k + (m - A[k] - 1));
    tmp = query(1, k - 1) + query(k, pos);
    ans = max(ans, tmp);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &A[i]);
    A[i] = max(A[i], i);
    B[i] = A[i] - i;
    p[i] = make_pair(B[i], i);
  }
  sort(p + 1, p + 1 + n);
  x = 1;
  for (int i = (1); i <= (n); i++) {
    k = p[i].second;
    if (A[k] < m) update(k);
    if (i == n || p[i].first != p[i + 1].first) {
      solve(x, i);
      x = i + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
