#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int x, y, n, m;
vector<int> v[N];
struct Tree {
  int l, r, num, flag;
} T[N * 4];
void build(int x, int l, int r) {
  T[x].l = l;
  T[x].r = r;
  if (l == r) {
    T[x].num = m + 1 - r;
    return;
  }
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  T[x].num = min(T[x * 2].num, T[x * 2 + 1].num);
}
void down(int x) {
  T[x * 2].num += T[x].flag;
  T[x * 2 + 1].num += T[x].flag;
  T[x * 2].flag += T[x].flag;
  T[x * 2 + 1].flag += T[x].flag;
  T[x].flag = 0;
}
void insert(int x, int l, int r) {
  if (T[x].l > r || l > T[x].r) return;
  if (T[x].l >= l && T[x].r <= r) {
    T[x].num--;
    T[x].flag--;
    return;
  }
  down(x);
  insert(x * 2, l, r);
  insert(x * 2 + 1, l, r);
  T[x].num = min(T[x * 2].num, T[x * 2 + 1].num);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", &x, &y), v[x].push_back(y);
  build(1, 0, m + 1);
  int ans = 0;
  for (int i = 0; i <= m + 1; i++) {
    for (int j : v[i]) insert(1, 0, j);
    ans = min(ans, i + T[1].num);
  }
  printf("%d\n", -ans);
}
