#include <bits/stdc++.h>   using namespace std;   const int N = 100002;   int arr[N], n, inc[N], decr[N];   int tree[4 * N];   int update(int pos, int l, int r, int x, int v) {     if (l > x || r < x) return tree[pos];     if (l == r) return tree[pos] = max(tree[pos], v);     int mid = (l + r) / 2;     return tree[pos] = max(update(pos * 2, l, mid, x, v),                            update(pos * 2 + 1, mid + 1, r, x, v));   }   int get(int pos, int l, int r, int qLow, int qHigh) {     if (l > qHigh || r < qLow) return 0;     if (l >= qLow && r <= qHigh) return tree[pos];     int mid = (l + r) / 2;     return max(get(pos * 2, l, mid, qLow, qHigh),                get(pos * 2 + 1, mid + 1, r, qLow, qHigh));   }   int bitonic() {     int i, max;     inc[1] = 1;     update(1, 0, n, arr[1], 1);     for (i = 2; i <= n; i++) {       int x = get(1, 0, n, 0, arr[i]);       inc[i] = x + 1;       update(1, 0, n, arr[i], inc[i]);     }     memset(tree, 0, sizeof tree);     decr[n] = 1;     update(1, 0, n, arr[n], 1);     for (i = n - 1; i > 0; i--) {       int x = get(1, 0, n, 0, arr[i]);       decr[i] = x + 1;       update(1, 0, n, arr[i], decr[i]);     }     max = 0;     for (i = 0; i <= n; i++)       if (inc[i] + decr[i] - 1 > max) max = inc[i] + decr[i] - 1;     return max;   }   int main() {     int a, b;     scanf( %d%d , &a, &n);     for (int i = 0; i < a; i++) {       int x, y;       scanf( %d%d , &x, &y);       arr[x]++, arr[y + 1]--;     }     for (int i = 1; i <= n; i++) arr[i] += arr[i - 1];     printf( %d , bitonic());     return 0;   }   