#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> PII; vector<PII> segs; int res;//被移除的树000 //合并区间 void merge(){ sort(segs.begin(),segs.end());//排序,默认按左端点升序 int bg = -1, ed = -1; for(auto seg : segs){ if(ed >= seg.first){//有交集 ed = max(ed, seg.second); }else{//无交集 if(bg != -1){ res += ed - bg + 1; } bg = seg.first; ed = seg.second; } } //加上最后一个区间 res += ed - bg + 1; } int main() { int L, M; cin >> L >> M; while(M --){ int a, b; scanf("%d%d", &a, &b); segs.push_back({a, b}); } merge(); cout << (L + 1) - res << endl;//一共有L+1棵树 return 0; } // 64 位输出请用 printf("%lld")