#include <iostream>
#include <cstdio>
#define lpos pos << 1
#define rpos pos << 1 | 1
using namespace std;
const int MAXN = 1e4 + 5;
int l, m, u, v;
struct tree
{
int l, r, val, tag;
}t[MAXN << 2];
inline void pushdown(int pos)
{
if (t[pos].tag)
{
t[lpos].val = t[rpos].val = t[pos].tag;
t[lpos].tag = t[rpos].tag = t[pos].tag;
t[pos].tag = 0;
}
}
inline void build(int pos, int l, int r)
{
t[pos].l = l, t[pos].r = r;
if (l == r)
{
t[pos].val = 1;
return;
}
int mid = (l + r) >> 1;
build(lpos, l, mid);
build(rpos, mid + 1, r);
t[pos].val = t[lpos].val + t[rpos].val;
}
inline void update(int pos, int L, int R)
{
int l = t[pos].l, r = t[pos].r;
if (l >= L && r <= R)
{
t[pos].val = t[pos].tag = 0;
return;
}
pushdown(pos);
int mid = (l + r) >> 1;
if (L <= mid)
{
update(lpos, L, R);
}
if (R > mid)
{
update(rpos, L, R);
}
t[pos].val = t[lpos].val + t[rpos].val;
}
int main()
{
scanf("%d%d", &l, &m);
l++;
build(1, 1, l);
while (m--)
{
scanf("%d%d", &u, &v);
u++, v++;
update(1, u, v);
}
printf("%d", t[1].val);
return 0;
}