#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,m = map(int, input().split())
l = [list(map(int,input().split())) for i in range(m)]

# n,mが10^5なのでO(n^2)は間に合わない
"""
ans = 0
for i in range(1,n+1):
    flg = True
    for j in range(m):
        if i < l[j][0] or i > l[j][1]:
            flg = False
    if (flg):
        ans+=1
print(ans)
"""

#lをO(m)で走査して上限、下限をあらかじめ確定しておく
up = 10**5+1
lo = 0

for i in range(m):
    if lo < l[i][0]:
        lo = l[i][0]
    if  up > l[i][1]:
        up = l[i][1]

"""
#わざわざ回す必要がない
ans = 0
for i in range(1,n+1):
    if i >= lo and i <= up:
        ans+=1
"""
if (up - lo >= 0):
    print(up -lo+1)
else:
    print(0)

 n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m list(map(int,input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l = [list(map(int,input().split())) for i in range(m)] l [list(map(int,input().split())) for i in range(m)] """
ans = 0
for i in range(1,n+1):
    flg = True
    for j in range(m):
        if i < l[j][0] or i > l[j][1]:
            flg = False
    if (flg):
        ans+=1
print(ans)
""" up = 10**5+1 up 10**5+1 10**5 10 5 1 lo = 0 lo 0 for i in range(m):
    if lo < l[i][0]:
        lo = l[i][0]
    if  up > l[i][1]:
        up = l[i][1] i range(m) range m if lo < l[i][0]:
        lo = l[i][0]
     lo < l[i][0] lo l[i][0] [i] l i 0 lo = l[i][0] lo l[i][0] [i] l i 0 if  up > l[i][1]:
        up = l[i][1] up > l[i][1] up l[i][1] [i] l i 1 up = l[i][1] up l[i][1] [i] l i 1 """
#わざわざ回す必要がない
ans = 0
for i in range(1,n+1):
    if i >= lo and i <= up:
        ans+=1
""" if (up - lo >= 0):
    print(up -lo+1)
else:
    print(0) up - lo >= 0 up - lo up lo 0 print(up -lo+1) print up -lo+1 up -lo up lo 1 print(0) print 0 l = [list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] l up = l[i][1] l[i][1] up m = map(int, input().split()) map(int, input().split()) m up = 10**5+1 10**5+1 up n,m = map(int, input().split()) map(int, input().split()) n lo = 0 0 lo lo = l[i][0] l[i][0] lo
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,m = map(int, input().split())
l = [list(map(int,input().split())) for i in range(m)]

# n,mが10^5なのでO(n^2)は間に合わない
"""
ans = 0
for i in range(1,n+1):
    flg = True
    for j in range(m):
        if i < l[j][0] or i > l[j][1]:
            flg = False
    if (flg):
        ans+=1
print(ans)
"""

#lをO(m)で走査して上限、下限をあらかじめ確定しておく
up = 10**5+1
lo = 0

for i in range(m):
    if lo < l[i][0]:
        lo = l[i][0]
    if  up > l[i][1]:
        up = l[i][1]

"""
#わざわざ回す必要がない
ans = 0
for i in range(1,n+1):
    if i >= lo and i <= up:
        ans+=1
"""
if (up - lo >= 0):
    print(up -lo+1)
else:
    print(0)


