
def solve():
    dp = [0] * N
    L = max(l)
    R = min(r)
    if L <= R:
        i = list(range(L,R+1))
        ans = len(i)
    else:
        ans = 0
    print(ans)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))
#    LR = [list(map(int, input().split())) for _ in range(M)]
    l,r = [0]*M, [0]*M
    for c in range(M):
        tmp = list(map(int, input().split()))
        l[c] = tmp[0]
        r[c] = tmp[1]
    solve()   def solve():
    dp = [0] * N
    L = max(l)
    R = min(r)
    if L <= R:
        i = list(range(L,R+1))
        ans = len(i)
    else:
        ans = 0
    print(ans) solve dp = [0] * N dp [0] * N [0] 0 N L = max(l) L max(l) max l R = min(r) R min(r) min r if L <= R:
        i = list(range(L,R+1))
        ans = len(i)
    else:
        ans = 0
     L <= R L R i = list(range(L,R+1)) i list(range(L,R+1)) list range(L,R+1) range L R+1 R 1 ans = len(i) ans len(i) len i ans = 0 ans 0 print(ans) print ans if __name__ == "__main__":
    N,M = list(map(int, input().split()))
#    LR = [list(map(int, input().split())) for _ in range(M)]
    l,r = [0]*M, [0]*M
    for c in range(M):
        tmp = list(map(int, input().split()))
        l[c] = tmp[0]
        r[c] = tmp[1]
    solve()   __name__ == "__main__" __name__ "__main__" N,M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M l,r = [0]*M, [0]*M l [0]*M [0] 0 M r [0]*M [0] 0 M for c in range(M):
        tmp = list(map(int, input().split()))
        l[c] = tmp[0]
        r[c] = tmp[1]
     c range(M) range M tmp = list(map(int, input().split())) tmp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split l[c] = tmp[0] l[c] l c tmp[0] tmp 0 r[c] = tmp[1] r[c] r c tmp[1] tmp 1 solve() solve N,M = list(map(int, input().split())) list(map(int, input().split())) N def solve():
    dp = [0] * N
    L = max(l)
    R = min(r)
    if L <= R:
        i = list(range(L,R+1))
        ans = len(i)
    else:
        ans = 0
    print(ans) def solve():
    dp = [0] * N
    L = max(l)
    R = min(r)
    if L <= R:
        i = list(range(L,R+1))
        ans = len(i)
    else:
        ans = 0
    print(ans) solve M = list(map(int, input().split())) list(map(int, input().split())) M tmp = list(map(int, input().split())) list(map(int, input().split())) tmp l,r = [0]*M, [0]*M [0]*M l r = [0]*M, [0]*M [0]*M r

def solve():
    dp = [0] * N
    L = max(l)
    R = min(r)
    if L <= R:
        i = list(range(L,R+1))
        ans = len(i)
    else:
        ans = 0
    print(ans)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))
#    LR = [list(map(int, input().split())) for _ in range(M)]
    l,r = [0]*M, [0]*M
    for c in range(M):
        tmp = list(map(int, input().split()))
        l[c] = tmp[0]
        r[c] = tmp[1]
    solve()  
