#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000;
int sum[(maxn << 2) + 60], add[(maxn << 2) + 60];
void push_up(int rt) {
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
return;
}
void push_down(int rt, int m) {
if (add[rt]) {
add[rt << 1] = add[rt];
add[rt << 1 | 1] = add[rt];
sum[rt << 1] = (m - (m >> 1)) * add[rt];
sum[rt << 1 | 1] = (m >> 1) * add[rt];
add[rt] = 0;
}
return;
}
void update(int a, int b, int c, int l, int r, int rt) {
if (a <= l && b >= r) {
sum[rt] = (r - l + 1) * c;
add[rt] = c;
return;
}
push_down(rt, r - l + 1);
int mid = (l + r) >> 1;
if (a <= mid) {
update(a, b, c, l, mid, rt << 1);
}
if (b > mid) {
update(a, b, c, mid + 1, r, rt << 1 | 1);
}
push_up(rt);
return;
}
int query(int a, int b, int l, int r, int rt) {
if (a <= l && b >= r) {
return sum[rt];
}
push_down(rt, r - l + 1);
int mid = (l + r) >> 1, ans = 0;
if (a <= mid) {
ans += query(a, b, l, mid, rt << 1);
}
if (b > mid) {
ans += query(a, b, mid + 1, r, rt << 1 | 1);
}
return ans;
}
int main(void) {
int n, m;
scanf("%d %d", &n, &m);
while (m--) {
int l, r;
scanf("%d %d", &l, &r);
update(l, r, 1, 0, n, 1);
}
printf("%d", n + 1 - query(0, n, 0, n, 1));
return 0;
}