n,m = map(int,input().split())
lr = []
for i in range(m):
    LR = list(map(int,input().split()))
    lr.append(LR)
min,max = 1,n
for i in range(m):
    if lr[i][0] > min:
        min = lr[i][0]
    if lr[i][1] < max:
        max = lr[i][1]
if min > max:
    print("0")
else:
    print(max - min + 1) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m lr = [] lr [] for i in range(m):
    LR = list(map(int,input().split()))
    lr.append(LR) i range(m) range m LR = list(map(int,input().split())) LR list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split lr.append(LR) lr.append lr append LR min,max = 1,n min 1 max n for i in range(m):
    if lr[i][0] > min:
        min = lr[i][0]
    if lr[i][1] < max:
        max = lr[i][1] i range(m) range m if lr[i][0] > min:
        min = lr[i][0]
     lr[i][0] > min lr[i][0] [i] lr i 0 min min = lr[i][0] min lr[i][0] [i] lr i 0 if lr[i][1] < max:
        max = lr[i][1] lr[i][1] < max lr[i][1] [i] lr i 1 max max = lr[i][1] max lr[i][1] [i] lr i 1 if min > max:
    print("0")
else:
    print(max - min + 1) min > max min max print("0") print "0" print(max - min + 1) print max - min + 1 max - min max min 1 min,max = 1,n 1 min LR = list(map(int,input().split())) list(map(int,input().split())) LR max = lr[i][1] lr[i][1] max min = lr[i][0] lr[i][0] min m = map(int,input().split()) map(int,input().split()) m max = 1,n n max n,m = map(int,input().split()) map(int,input().split()) n lr = [] [] lr
n,m = map(int,input().split())
lr = []
for i in range(m):
    LR = list(map(int,input().split()))
    lr.append(LR)
min,max = 1,n
for i in range(m):
    if lr[i][0] > min:
        min = lr[i][0]
    if lr[i][1] < max:
        max = lr[i][1]
if min > max:
    print("0")
else:
    print(max - min + 1)