r=input().split()
N=int(r[0])
M=int(r[1])
data=[[int(s) for s in input().split()] for i in range(M)]
left=[]
right=[]
for i in range(M):
    left.append(data[i][0])
    right.append(data[i][1])
if min(right)-max(left)+1<=0:
    print(0)
else:
    print(min(right)-max(left)+1) r=input().split() r input().split() ().split () input split N=int(r[0]) N int(r[0]) int r[0] r 0 M=int(r[1]) M int(r[1]) int r[1] r 1 [int(s) for s in input().split()] for i in range(M) for i in range(M) i range(M) range M for i in range(M) [int(s) for s in input().split()] data=[[int(s) for s in input().split()] for i in range(M)] data [[int(s) for s in input().split()] for i in range(M)] left=[] left [] right=[] right [] for i in range(M):
    left.append(data[i][0])
    right.append(data[i][1]) i range(M) range M left.append(data[i][0]) left.append left append data[i][0] [i] data i 0 right.append(data[i][1]) right.append right append data[i][1] [i] data i 1 if min(right)-max(left)+1<=0:
    print(0)
else:
    print(min(right)-max(left)+1) min(right)-max(left)+1<=0 min(right)-max(left)+1 min(right)-max(left) min(right) min right max(left) max left 1 0 print(0) print 0 print(min(right)-max(left)+1) print min(right)-max(left)+1 min(right)-max(left) min(right) min right max(left) max left 1 N=int(r[0]) int(r[0]) N right=[] [] right data=[[int(s) for s in input().split()] for i in range(M)] [[int(s) for s in input().split()] for i in range(M)] data left=[] [] left M=int(r[1]) int(r[1]) M r=input().split() input().split() r
r=input().split()
N=int(r[0])
M=int(r[1])
data=[[int(s) for s in input().split()] for i in range(M)]
left=[]
right=[]
for i in range(M):
    left.append(data[i][0])
    right.append(data[i][1])
if min(right)-max(left)+1<=0:
    print(0)
else:
    print(min(right)-max(left)+1)