import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    min_id = 0
    max_id = 10**5
    for _ in range(M):
        L, R = map(int, input().split())
        if min_id < L:
            min_id = L
        if max_id > R:
            max_id = R
    if min_id > max_id:
        print(0)
    else:
        print(max_id - min_id + 1)


if __name__ == '__main__':
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    N, M = map(int, input().split())
    min_id = 0
    max_id = 10**5
    for _ in range(M):
        L, R = map(int, input().split())
        if min_id < L:
            min_id = L
        if max_id > R:
            max_id = R
    if min_id > max_id:
        print(0)
    else:
        print(max_id - min_id + 1) main N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M min_id = 0 min_id 0 max_id = 10**5 max_id 10**5 10 5 for _ in range(M):
        L, R = map(int, input().split())
        if min_id < L:
            min_id = L
        if max_id > R:
            max_id = R
     _ range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R if min_id < L:
            min_id = L
         min_id < L min_id L min_id = L min_id L if max_id > R:
            max_id = R
     max_id > R max_id R max_id = R max_id R if min_id > max_id:
        print(0)
    else:
        print(max_id - min_id + 1) min_id > max_id min_id max_id print(0) print 0 print(max_id - min_id + 1) print max_id - min_id + 1 max_id - min_id max_id min_id 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input = sys.stdin.readline sys.stdin.readline input def main():
    N, M = map(int, input().split())
    min_id = 0
    max_id = 10**5
    for _ in range(M):
        L, R = map(int, input().split())
        if min_id < L:
            min_id = L
        if max_id > R:
            max_id = R
    if min_id > max_id:
        print(0)
    else:
        print(max_id - min_id + 1) def main():
    N, M = map(int, input().split())
    min_id = 0
    max_id = 10**5
    for _ in range(M):
        L, R = map(int, input().split())
        if min_id < L:
            min_id = L
        if max_id > R:
            max_id = R
    if min_id > max_id:
        print(0)
    else:
        print(max_id - min_id + 1) main
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    min_id = 0
    max_id = 10**5
    for _ in range(M):
        L, R = map(int, input().split())
        if min_id < L:
            min_id = L
        if max_id > R:
            max_id = R
    if min_id > max_id:
        print(0)
    else:
        print(max_id - min_id + 1)


if __name__ == '__main__':
    main()
