import sys
import math
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    L = 1
    R = 10 ** 5 + 1

    for i in range(M):
        l, r = map(int, input().split())
        L = max(l, L)
        R = min(r, R)

    print(max(R-L+1,0))


if __name__ == "__main__":
    main() import sys sys import math math import itertools itertools def input():
    return sys.stdin.readline().rstrip() input return sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def main():
    N, M = map(int, input().split())
    L = 1
    R = 10 ** 5 + 1

    for i in range(M):
        l, r = map(int, input().split())
        L = max(l, L)
        R = min(r, R)

    print(max(R-L+1,0)) main N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L = 1 L 1 R = 10 ** 5 + 1 R 10 ** 5 + 1 10 ** 5 10 5 1 for i in range(M):
        l, r = map(int, input().split())
        L = max(l, L)
        R = min(r, R)

     i range(M) range M l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r L = max(l, L) L max(l, L) max l L R = min(r, R) R min(r, R) min r R print(max(R-L+1,0)) print max(R-L+1,0) max R-L+1 R-L R L 1 0 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M = map(int, input().split())
    L = 1
    R = 10 ** 5 + 1

    for i in range(M):
        l, r = map(int, input().split())
        L = max(l, L)
        R = min(r, R)

    print(max(R-L+1,0)) def main():
    N, M = map(int, input().split())
    L = 1
    R = 10 ** 5 + 1

    for i in range(M):
        l, r = map(int, input().split())
        L = max(l, L)
        R = min(r, R)

    print(max(R-L+1,0)) main def input():
    return sys.stdin.readline().rstrip() def input():
    return sys.stdin.readline().rstrip() input
import sys
import math
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    L = 1
    R = 10 ** 5 + 1

    for i in range(M):
        l, r = map(int, input().split())
        L = max(l, L)
        R = min(r, R)

    print(max(R-L+1,0))


if __name__ == "__main__":
    main()
