
N, M = map(int, input().split())

L = [0] * M
R = [0] * M


LR = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())

ans = min(R) - max(L) 
if ans >=0:
    print(ans + 1)
    
else:
    print(0)
    
#print(max(L))
#print(min(R)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L = [0] * M L [0] * M [0] 0 M R = [0] * M R [0] * M [0] 0 M LR = [0] * M LR [0] * M [0] 0 M for i in range(M):
    L[i], R[i] = map(int, input().split()) i range(M) range M L[i], R[i] = map(int, input().split()) L[i] L i map(int, input().split()) map int input().split() ().split () input split R[i] R i ans = min(R) - max(L) ans min(R) - max(L) min(R) min R max(L) max L if ans >=0:
    print(ans + 1)
    
else:
    print(0)
    
#print(max(L))
#print(min(R)) ans >=0 ans 0 print(ans + 1) print ans + 1 ans 1 print(0) print 0 R = [0] * M [0] * M R N, M = map(int, input().split()) map(int, input().split()) N L = [0] * M [0] * M L LR = [0] * M [0] * M LR ans = min(R) - max(L) min(R) - max(L) ans M = map(int, input().split()) map(int, input().split()) M

N, M = map(int, input().split())

L = [0] * M
R = [0] * M


LR = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())

ans = min(R) - max(L) 
if ans >=0:
    print(ans + 1)
    
else:
    print(0)
    
#print(max(L))
#print(min(R))