#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 123;
int n, m;
pair<int, int> a[maxn];
void ReadData() {
  cin >> n >> m;
  for (int i = 1, _b = n; i <= _b; ++i) cin >> a[i].first >> a[i].second;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second == b.second) return a.first > b.first;
  return a.second > b.second;
}
class segmentTree {
 public:
  int l[maxn * 4], h[maxn * 4];
  int it[maxn * 4];
  int lazy[maxn * 4];
  void buildTree(const int x, const int lo, const int hi, int val = 0) {
    l[x] = lo;
    h[x] = hi;
    lazy[x] = 0;
    if (lo == hi) {
      it[x] = lo;
      if (val) it[x] = 0;
    } else {
      int mid = (lo + hi) >> 1;
      buildTree((x << 1), lo, mid);
      buildTree(((x << 1) | 1), mid + 1, hi);
      it[x] = min(it[(x << 1)], it[((x << 1) | 1)]);
    }
  }
  void add(const int x, const int val) {
    it[x] += val;
    lazy[x] += val;
  }
  void pushDown(const int x) {
    if (lazy[x] != 0) {
      add((x << 1), lazy[x]);
      add(((x << 1) | 1), lazy[x]);
      lazy[x] = 0;
    }
  }
  void update(const int x, const int u, const int v, const int val) {
    if (l[x] > v || h[x] < u) return;
    if (u <= l[x] && h[x] <= v) {
      add(x, val);
      return;
    }
    pushDown(x);
    update((x << 1), u, v, val);
    update(((x << 1) | 1), u, v, val);
    it[x] = min(it[(x << 1)], it[((x << 1) | 1)]);
  }
  int get(const int x, const int u, const int v) {
    if (l[x] > v || h[x] < u) return maxn;
    if (u <= l[x] && h[x] <= v) {
      return it[x];
    }
    pushDown(x);
    return min(get((x << 1), u, v), get(((x << 1) | 1), u, v));
  }
} tree, tree2;
void Process() {
  tree.buildTree(1, 0, 200000);
  tree2.buildTree(1, 0, 200000, 1);
  int minVal = maxn;
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1, _b = n; i <= _b; ++i) {
    tree.update(1, a[i].first, 200000, -1);
    tree2.update(1, a[i].first, 200000, -1);
    minVal = min(minVal, tree.get(1, 0, a[i].second - 1) + m - a[i].second + 1);
    minVal = min(minVal, tree.get(1, a[i].second, 200000) + m);
  }
  if (minVal >= 0) minVal = 0;
  cout << -minVal << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ReadData();
  Process();
  return 0;
}
