干草堆
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
ll res, cnt;
int n, m;
int x, y;
int b[N];
int main()
{
cin >> n >> m;
while (m -- )
{
cin >> x >> y;
b[x] ++, b[y + 1] --; // 建立差分数组
}
for (int i = 1; i <= n; i ++ ) b[i] += b[i - 1]; // 求原数组
nth_element(b + 1, b + n / 2 + 1, b + n + 1); // 求中位数
cout << b[n / 2 + 1];
return 0;
}