#include <bits/stdc++.h>
using namespace std;
int n, m, ans, a[200009], q[200009], c[200009];
void ins(int x) {
  for (; x <= n; x += x & -x) c[x]++;
}
int getsum(int x) {
  int y = 0;
  for (; x; x ^= x & -x) y += c[x];
  return y;
}
bool cmp(int x, int y) {
  return a[x] - x < a[y] - y || a[x] - x == a[y] - y && x < y;
}
int main() {
  scanf("%d%d", &n, &m);
  int i;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) q[i] = i;
  sort(q + 1, q + n + 1, cmp);
  int ans = 0;
  for (int l = 1; l <= n; l++) {
    i = q[l];
    ins(i);
    int j = i + min(m - i, m - a[i]) - 1;
    if (j >= 1) ans = max(ans, getsum(min(j, n)));
  }
  printf("%d\n", ans);
  return 0;
}
