You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
708 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
struct Node {
int st;
int ed;
} seg[N];
bool cmp(Node a, Node b) {
if (a.st == b.st) return a.ed < b.ed;
return a.st < b.st;
}
int m, L;
int main() {
cin >> L >> m;
for (int i = 0; i < m; i++) cin >> seg[i].st >> seg[i].ed;
sort(seg, seg + m, cmp);
int res = L + 1;
int st = seg[0].st, ed = seg[0].ed;
for (int i = 1; i < m; i++)
if (seg[i].st <= ed)
ed = max(seg[i].ed, ed);
else {
res -= ed - st + 1;
st = seg[i].st, ed = seg[i].ed;
}
res -= ed - st + 1;
cout << res << endl;
return 0;
}