def resolve():
    '''
    code here
    '''
    N , M = [int(item) for item in input().split()]
    LRs = [[int(item) for item in input().split()] for _ in range(M)]

    L_max = 0
    R_min = N

    for L, R in LRs:
        L_max = max(L_max, L)
        R_min = min(R_min, R)

    delta = R_min - L_max
    if delta >= 0:
        print(delta + 1)
    else:
        print(0)



if __name__ == "__main__":
    resolve() def resolve():
    '''
    code here
    '''
    N , M = [int(item) for item in input().split()]
    LRs = [[int(item) for item in input().split()] for _ in range(M)]

    L_max = 0
    R_min = N

    for L, R in LRs:
        L_max = max(L_max, L)
        R_min = min(R_min, R)

    delta = R_min - L_max
    if delta >= 0:
        print(delta + 1)
    else:
        print(0) resolve '''
    code here
    ''' int(item) for item in input().split() for item in input().split() item input().split() ().split () input split for item in input().split() int(item) int item N , M = [int(item) for item in input().split()] N [int(item) for item in input().split()] M [int(item) for item in input().split()] for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) [int(item) for item in input().split()] LRs = [[int(item) for item in input().split()] for _ in range(M)] LRs [[int(item) for item in input().split()] for _ in range(M)] L_max = 0 L_max 0 R_min = N R_min N for L, R in LRs:
        L_max = max(L_max, L)
        R_min = min(R_min, R)

     L R LRs L_max = max(L_max, L) L_max max(L_max, L) max L_max L R_min = min(R_min, R) R_min min(R_min, R) min R_min R delta = R_min - L_max delta R_min - L_max R_min L_max if delta >= 0:
        print(delta + 1)
    else:
        print(0) delta >= 0 delta 0 print(delta + 1) print delta + 1 delta 1 print(0) print 0 if __name__ == "__main__":
    resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
    '''
    code here
    '''
    N , M = [int(item) for item in input().split()]
    LRs = [[int(item) for item in input().split()] for _ in range(M)]

    L_max = 0
    R_min = N

    for L, R in LRs:
        L_max = max(L_max, L)
        R_min = min(R_min, R)

    delta = R_min - L_max
    if delta >= 0:
        print(delta + 1)
    else:
        print(0) def resolve():
    '''
    code here
    '''
    N , M = [int(item) for item in input().split()]
    LRs = [[int(item) for item in input().split()] for _ in range(M)]

    L_max = 0
    R_min = N

    for L, R in LRs:
        L_max = max(L_max, L)
        R_min = min(R_min, R)

    delta = R_min - L_max
    if delta >= 0:
        print(delta + 1)
    else:
        print(0) resolve
def resolve():
    '''
    code here
    '''
    N , M = [int(item) for item in input().split()]
    LRs = [[int(item) for item in input().split()] for _ in range(M)]

    L_max = 0
    R_min = N

    for L, R in LRs:
        L_max = max(L_max, L)
        R_min = min(R_min, R)

    delta = R_min - L_max
    if delta >= 0:
        print(delta + 1)
    else:
        print(0)



if __name__ == "__main__":
    resolve()
