data=input().split()
N=int(data[0])
M=int(data[1])
data_gate=[input().split() for i in range(M)]
data_min=[]
data_max=[]
for i in range(M):
    data_min.append(int(data_gate[i][0]))
    data_max.append(int(data_gate[i][1]))
m=max(data_min)
M=min(data_max)
if M>=m:
    ans=M-m+1
else:
    ans=0
print(ans) data=input().split() data input().split() ().split () input split N=int(data[0]) N int(data[0]) int data[0] data 0 M=int(data[1]) M int(data[1]) int data[1] data 1 input().split() for i in range(M) for i in range(M) i range(M) range M for i in range(M) input().split() ().split () input split data_gate=[input().split() for i in range(M)] data_gate [input().split() for i in range(M)] data_min=[] data_min [] data_max=[] data_max [] for i in range(M):
    data_min.append(int(data_gate[i][0]))
    data_max.append(int(data_gate[i][1])) i range(M) range M data_min.append(int(data_gate[i][0])) data_min.append data_min append int(data_gate[i][0]) int data_gate[i][0] [i] data_gate i 0 data_max.append(int(data_gate[i][1])) data_max.append data_max append int(data_gate[i][1]) int data_gate[i][1] [i] data_gate i 1 m=max(data_min) m max(data_min) max data_min M=min(data_max) M min(data_max) min data_max if M>=m:
    ans=M-m+1
else:
    ans=0 M>=m M m ans=M-m+1 ans M-m+1 M-m M m 1 ans=0 ans 0 print(ans) print ans M=min(data_max) min(data_max) M M=int(data[1]) int(data[1]) M data_gate=[input().split() for i in range(M)] [input().split() for i in range(M)] data_gate ans=0 0 ans data_min=[] [] data_min data=input().split() input().split() data ans=M-m+1 M-m+1 ans data_max=[] [] data_max m=max(data_min) max(data_min) m N=int(data[0]) int(data[0]) N
data=input().split()
N=int(data[0])
M=int(data[1])
data_gate=[input().split() for i in range(M)]
data_min=[]
data_max=[]
for i in range(M):
    data_min.append(int(data_gate[i][0]))
    data_max.append(int(data_gate[i][1]))
m=max(data_min)
M=min(data_max)
if M>=m:
    ans=M-m+1
else:
    ans=0
print(ans)