#include <iostream>
#include <cstdio>

int main() {
    int tree[10001]; //1表示活着,0表示死了
    int L,M; //种L棵树, M组数据
    scanf("%d%d", &L, &M);
    //种L + 1棵树
    for(int i = 0; i <= L; i++){
        tree[i] = 1;
    }
    for(int index = 0; index < M; index++){
        int left, right;
        scanf("%d%d", &left, &right);
        for(int i = left; i <= right; i++){
            tree[i] = 0;
        }
    }
    int count = 0;
    for(int i = 0; i <= L; i++){
        if(1 == tree[i]){
            count++;
        }
    }
    printf("%d", count);
}