#include <bits/stdc++.h>
using namespace std;
int n, m;
struct node {
  int l, r;
  bool operator<(const node &rhs) const { return l < rhs.l; }
} a[200050];
int b[200050];
struct segment_tree {
  int tt[200050 << 2], tag[200050 << 2];
  void maketree(int x, int lb, int rb) {
    if (lb == rb) {
      tt[x] = b[lb];
      tag[x] = 0;
      return;
    }
    int mid = (lb + rb) / 2;
    maketree(2 * x, lb, mid);
    maketree(2 * x + 1, mid + 1, rb);
    tt[x] = min(tt[2 * x], tt[2 * x + 1]);
  }
  void pushdown(int x) {
    int k = tag[x];
    tag[x] = 0;
    tt[2 * x] += k;
    tag[2 * x] += k;
    tt[2 * x + 1] += k;
    tag[2 * x + 1] += k;
  }
  void add(int x, int l, int r, int k, int lb, int rb) {
    if (l <= lb && rb <= r) {
      tt[x] += k;
      tag[x] += k;
      return;
    }
    if (lb > r || rb < l) return;
    pushdown(x);
    int mid = (lb + rb) / 2;
    add(2 * x, l, r, k, lb, mid);
    add(2 * x + 1, l, r, k, mid + 1, rb);
    tt[x] = min(tt[2 * x], tt[2 * x + 1]);
  }
  int query(int x, int l, int r, int lb, int rb) {
    if (l <= lb && rb <= r) {
      return tt[x];
    }
    if (lb > r || rb < l) return 10000007;
    pushdown(x);
    int mid = (lb + rb) / 2;
    return min(query(2 * x, l, r, lb, mid),
               query(2 * x + 1, l, r, mid + 1, rb));
  }
} ylq;
int main() {
  scanf("%d %d", &m, &n);
  for (register int i = 1; i <= m; i++) scanf("%d %d", &a[i].l, &a[i].r);
  sort(a + 1, a + m + 1);
  int cnt = 0;
  for (register int i = n + 1; i >= 0; i--) b[i] = cnt++;
  ylq.maketree(1, 0, n + 1);
  int ans = 0;
  for (register int i = 1; i <= m; i++) {
    ylq.add(1, 0, a[i].r, -1, 0, n + 1);
    int ming = ylq.query(1, 0, n + 1, 0, n + 1);
    if (a[i].l + ming < ans) ans = a[i].l + ming;
  }
  printf("%d\n", -ans);
}
