#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, x, y;
vector<int> ins[N];
namespace seg {
int a[N * 4], tag[N * 4];
void build(int rt, int l, int r) {
  a[rt] = l;
  if (l == r) return;
  int mid = l + r >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  a[rt] = min(a[rt << 1], a[rt << 1 | 1]);
}
inline void pushdown(int rt) {
  if (!tag[rt]) return;
  a[rt << 1] += tag[rt], tag[rt << 1] += tag[rt];
  a[rt << 1 | 1] += tag[rt], tag[rt << 1 | 1] += tag[rt];
  tag[rt] = 0;
}
void modify(int rt, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) return;
  if (l >= ql && r <= qr) return (void)(a[rt] -= 1, tag[rt] -= 1);
  pushdown(rt);
  int mid = l + r >> 1;
  modify(rt << 1, l, mid, ql, qr);
  modify(rt << 1 | 1, mid + 1, r, ql, qr);
  a[rt] = min(a[rt << 1], a[rt << 1 | 1]);
}
int query(int rt, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) return 1e9;
  if (l >= ql && r <= qr) return a[rt];
  pushdown(rt);
  int mid = l + r >> 1;
  return min(query(rt << 1, l, mid, ql, qr),
             query(rt << 1 | 1, mid + 1, r, ql, qr));
}
}  // namespace seg
int main() {
  scanf("%d%d", &n, &m);
  ++m;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    y = m - y;
    ins[x].push_back(y);
  }
  seg ::build(1, 0, m);
  int ans = m - 1 - n;
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j < (int)ins[i].size(); ++j) {
      int pos = ins[i][j];
      seg ::modify(1, 0, m, pos, m);
    }
    ans = min(ans, i + seg ::query(1, 0, m, 0, m - i));
  }
  printf("%d\n", max(0, -ans));
  return 0;
}
