def solve():
    N, M = map(int, input().split())
    Count = [0] * (N + 1)
    for i in range(M):
        l, r = map(int, input().split())
        Count[l-1] += 1
        Count[r] -= 1
    ans = 0
    if Count[0] == M: ans = 1
    for i in range(1, N):
        Count[i] += Count[i-1]
        if Count[i] == M: ans += 1
    print(ans)


if __name__ == "__main__":
    solve() def solve():
    N, M = map(int, input().split())
    Count = [0] * (N + 1)
    for i in range(M):
        l, r = map(int, input().split())
        Count[l-1] += 1
        Count[r] -= 1
    ans = 0
    if Count[0] == M: ans = 1
    for i in range(1, N):
        Count[i] += Count[i-1]
        if Count[i] == M: ans += 1
    print(ans) solve N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M Count = [0] * (N + 1) Count [0] * (N + 1) [0] 0 N + 1 N 1 for i in range(M):
        l, r = map(int, input().split())
        Count[l-1] += 1
        Count[r] -= 1
     i range(M) range M l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r Count[l-1] += 1 Count[l-1] Count l-1 l 1 1 Count[r] -= 1 Count[r] Count r 1 ans = 0 ans 0 if Count[0] == M: ans = 1
     Count[0] == M Count[0] Count 0 M for i in range(1, N):
        Count[i] += Count[i-1]
        if Count[i] == M: ans += 1
     i range(1, N) range 1 N Count[i] += Count[i-1] Count[i] Count i Count[i-1] Count i-1 i 1 if Count[i] == M: ans += 1
     Count[i] == M Count[i] Count i M print(ans) print ans if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def solve():
    N, M = map(int, input().split())
    Count = [0] * (N + 1)
    for i in range(M):
        l, r = map(int, input().split())
        Count[l-1] += 1
        Count[r] -= 1
    ans = 0
    if Count[0] == M: ans = 1
    for i in range(1, N):
        Count[i] += Count[i-1]
        if Count[i] == M: ans += 1
    print(ans) def solve():
    N, M = map(int, input().split())
    Count = [0] * (N + 1)
    for i in range(M):
        l, r = map(int, input().split())
        Count[l-1] += 1
        Count[r] -= 1
    ans = 0
    if Count[0] == M: ans = 1
    for i in range(1, N):
        Count[i] += Count[i-1]
        if Count[i] == M: ans += 1
    print(ans) solve
def solve():
    N, M = map(int, input().split())
    Count = [0] * (N + 1)
    for i in range(M):
        l, r = map(int, input().split())
        Count[l-1] += 1
        Count[r] -= 1
    ans = 0
    if Count[0] == M: ans = 1
    for i in range(1, N):
        Count[i] += Count[i-1]
        if Count[i] == M: ans += 1
    print(ans)


if __name__ == "__main__":
    solve()