#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 0x3f3f3f3f;
struct SegmentTree {
  struct Node {
    Node *left_child, *right_child;
    int left, right, mid, max;
  };
  Node *root;
  int left_bound, right_bound;
  void build(Node *&p, int left, int right) {
    p = new Node;
    p->left = left;
    p->right = right;
    p->mid = (left + right) / 2;
    if (left == right) {
      p->max = 0 - (right_bound - left);
      p->left_child = p->right_child = nullptr;
    } else {
      build(p->left_child, p->left, p->mid);
      build(p->right_child, p->mid + 1, p->right);
      p->max = max(p->left_child->max, p->right_child->max);
    }
  }
  explicit SegmentTree(int left, int right)
      : left_bound(left), right_bound(right) {
    build(root, left, right);
  }
  void destroy(Node *p) {
    if (p) {
      destroy(p->left_child);
      destroy(p->right_child);
      delete p;
    }
  }
  ~SegmentTree() { destroy(root); }
  void insert(Node *p, int pos) {
    if (p->left == p->right) {
      ++p->max;
    } else {
      insert(p->left_child, pos);
      if (pos > p->mid) insert(p->right_child, pos);
      p->max = max(p->left_child->max, p->right_child->max);
    }
  }
  void insert(int pos) { insert(root, pos); }
  int query() { return root->max; }
  void traverse(Node *p, int sp) {
    if (!p) return;
    traverse(p->left_child, sp + 1);
    for (int i = 0; i < sp; ++i) cout << "  ";
    cout << '[' << p->left << ", " << p->right << "] " << p->max << endl;
    traverse(p->right_child, sp + 1);
  }
  void traverse() {
    traverse(root, 0);
    cout << endl;
  }
};
struct Wish {
  int l, r;
} wishes[200000];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> wishes[i].l >> wishes[i].r;
  sort(wishes, wishes + n,
       [](const Wish &x, const Wish &y) { return x.l < y.l; });
  int ans = max(n - m, 0);
  SegmentTree sgt(0, m + 1);
  for (int i = 0, j = 0; i <= m + 1; ++i) {
    for (; j < n && wishes[j].l == i; ++j) sgt.insert(wishes[j].r);
    ans = max(ans, sgt.query() - i);
  }
  cout << ans << endl;
  return 0;
}
