# coding: utf-8

def main():
    N, M = map(int, input().split())
    imos = [0] * (N + 2)
    ans = 0

    for _ in range(M):
        l, r = map(int, input().split())
        imos[l] += 1
        imos[r + 1] -= 1

    for i in range(1, N + 2):
        imos[i] += imos[i - 1]
        if imos[i] == M and i != N + 1:
            ans += 1
    
    print(ans)

if __name__ == "__main__":
    main() def main():
    N, M = map(int, input().split())
    imos = [0] * (N + 2)
    ans = 0

    for _ in range(M):
        l, r = map(int, input().split())
        imos[l] += 1
        imos[r + 1] -= 1

    for i in range(1, N + 2):
        imos[i] += imos[i - 1]
        if imos[i] == M and i != N + 1:
            ans += 1
    
    print(ans) main N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M imos = [0] * (N + 2) imos [0] * (N + 2) [0] 0 N + 2 N 2 ans = 0 ans 0 for _ in range(M):
        l, r = map(int, input().split())
        imos[l] += 1
        imos[r + 1] -= 1

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

    for _ in range(M):
        l, r = map(int, input().split())
        imos[l] += 1
        imos[r + 1] -= 1

    for i in range(1, N + 2):
        imos[i] += imos[i - 1]
        if imos[i] == M and i != N + 1:
            ans += 1
    
    print(ans) def main():
    N, M = map(int, input().split())
    imos = [0] * (N + 2)
    ans = 0

    for _ in range(M):
        l, r = map(int, input().split())
        imos[l] += 1
        imos[r + 1] -= 1

    for i in range(1, N + 2):
        imos[i] += imos[i - 1]
        if imos[i] == M and i != N + 1:
            ans += 1
    
    print(ans) main
# coding: utf-8

def main():
    N, M = map(int, input().split())
    imos = [0] * (N + 2)
    ans = 0

    for _ in range(M):
        l, r = map(int, input().split())
        imos[l] += 1
        imos[r + 1] -= 1

    for i in range(1, N + 2):
        imos[i] += imos[i - 1]
        if imos[i] == M and i != N + 1:
            ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()
