//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

struct node {
  int v, lz;
} seg[N];

void merge(node& x, node& y, node& z) {
  x.v = min(y.v, z.v);
}

void build(int l, int r, int k) {
  seg[k].lz = 0;
  if (l == r) {
    seg[k] = {-l, 0};
    return;
  }
  int m = (l+r) / 2;
  build(l, m, k*2);
  build(m+1, r, k*2+1);
  merge(seg[k], seg[k*2], seg[k*2+1]);
}

void prop(int l, int r, int k) {
  if (l != r) {
    seg[k*2].lz += seg[k].lz;
    seg[k*2+1].lz += seg[k].lz;
  }
  seg[k].v += seg[k].lz;
  seg[k].lz = 0;
}

void upd(int l, int r, int k, int a, int b) {
  if (seg[k].lz) prop(l,r,k);
  if (b < l || r < a) return;
  if (a <= l && r <= b) {
    seg[k].lz--;
    prop(l,r,k);
    return;
  }
  int m = (l+r) / 2;
  upd(l, m, k*2, a, b);
  upd(m+1, r, k*2+1, a, b);
  merge(seg[k], seg[k*2], seg[k*2+1]);
}

int qry(int l, int r, int k, int a, int b) {
  if (seg[k].lz) prop(l,r,k);
  if (b < a || b < l || r < a) return N;
  if (a <= l && r <= b) return seg[k].v;
  int m = (l+r) / 2;
  return min(qry(l,m,k*2,a,b), qry(m+1,r,k*2+1,a,b));
}

array<int,2> a[N];

int main() {
  int n, m; scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i][0], &a[i][1]);
  }
  build(1, m, 1);
  sort(a+1, a+n+1);
  int ans = m - n;
  int j = 1;
  for (int i = 0; i < m; i++) {
    while (j <= n && a[j][0] == i)
      upd(1, m, 1, 1, a[j][1]), j++;
    ans = min(ans, i + m+1 + qry(1, m, 1, i+1, m));
  }
  printf("%d\n", max(-ans, 0));
  return 0;
}

/*
4 4
0 3
2 3
1 3
3 4
*/