#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 1e9 + 7;
int mx[maxn << 2], lazy[maxn << 2];
int n, m, t;
vector<int> g[maxn];
void build(int k, int lef, int rig) {
  if (lef == rig) {
    mx[k] = t - lef + 1;
    return;
  }
  int mid = (lef + rig) >> 1;
  build(k << 1, lef, mid);
  build(k << 1 | 1, mid + 1, rig);
  mx[k] = max(mx[k << 1], mx[k << 1 | 1]);
}
void pushDown(int k) {
  if (lazy[k]) {
    mx[k << 1] += lazy[k];
    mx[k << 1 | 1] += lazy[k];
    lazy[k << 1] += lazy[k];
    lazy[k << 1 | 1] += lazy[k];
    lazy[k] = 0;
  }
}
void update(int k, int lef, int rig, int l, int r, int c) {
  if (l <= lef && r >= rig) {
    mx[k] += c;
    lazy[k] += c;
    return;
  }
  pushDown(k);
  int mid = (lef + rig) >> 1;
  if (l <= mid) update(k << 1, lef, mid, l, r, c);
  if (r > mid) update(k << 1 | 1, mid + 1, rig, l, r, c);
  mx[k] = max(mx[k << 1], mx[k << 1 | 1]);
}
int query(int k, int lef, int rig, int l, int r) {
  if (l <= lef && r >= rig) {
    return mx[k];
  }
  pushDown(k);
  int ans = -inf;
  int mid = (lef + rig) >> 1;
  if (l <= mid) ans = max(ans, query(k << 1, lef, mid, l, r));
  if (r > mid) ans = max(ans, query(k << 1 | 1, mid + 1, rig, l, r));
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  t = max(n, m);
  int l, r;
  build(1, 1, t);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l, &r), g[r].push_back(l);
    if (l) update(1, 1, t, 1, l, -1);
  }
  int ans = -inf;
  int sum = 0;
  for (int i = 1; i <= t; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (g[i][j]) update(1, 1, t, 1, g[i][j], 1);
      sum++;
    }
    ans = max(ans, query(1, 1, t, 1, i) - (t - i) - sum);
  }
  printf("%d\n", t - m + ans);
  return 0;
}
