#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200010;
int n, m;
int maxx[Maxn << 2], la[Maxn << 2];
vector<int> vec[Maxn];
int _max(int x, int y) { return x > y ? x : y; }
void build_tree(int now, int L, int R) {
  if (L < R) {
    int mid = L + R >> 1, lc = now << 1, rc = now << 1 | 1;
    build_tree(lc, L, mid);
    build_tree(rc, mid + 1, R);
    maxx[now] = maxx[lc];
  } else
    maxx[now] = -L;
}
void push_down(int now) {
  if (la[now] != 0) {
    int lc = now << 1, rc = now << 1 | 1;
    maxx[lc] += la[now];
    maxx[rc] += la[now];
    la[lc] += la[now];
    la[rc] += la[now];
    la[now] = 0;
  }
}
void chg(int now, int L, int R, int l, int r) {
  if (L == l && R == r) {
    maxx[now]++;
    la[now]++;
    return;
  }
  push_down(now);
  int mid = L + R >> 1, lc = now << 1, rc = now << 1 | 1;
  if (r <= mid)
    chg(lc, L, mid, l, r);
  else if (l > mid)
    chg(rc, mid + 1, R, l, r);
  else
    chg(lc, L, mid, l, mid), chg(rc, mid + 1, R, mid + 1, r);
  maxx[now] = _max(maxx[lc], maxx[rc]);
}
int qry(int now, int L, int R, int r) {
  if (R == r) return maxx[now];
  int mid = L + R >> 1, lc = now << 1, rc = now << 1 | 1;
  if (r <= mid)
    return qry(lc, L, mid, r);
  else
    return _max(maxx[lc], qry(rc, mid + 1, R, r));
}
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    vec[y].push_back(x);
  }
  build_tree(1, 0, m);
  int ans = 0;
  for (i = m + 1; i >= 1; i--) {
    for (j = 0; j < vec[i].size(); j++) {
      int x = vec[i][j];
      chg(1, 0, m, x, i - 1);
    }
    int res = qry(1, 0, m, i - 1);
    ans = _max(ans, res - (m - i + 1));
  }
  printf("%d\n", ans);
  return 0;
}
