N, M = map(int, input().split())
L, R = [0]*M, [0]*M
A = set(range(N))
lm, rm = 0, N
for i in range(M):
    L[i], R[i] = map(int, input().split())
    lm = max(lm, L[i])
    rm = min(rm, R[i])
if lm <= rm:
    print(rm-lm+1)
else:
    print(0) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L, R = [0]*M, [0]*M L [0]*M [0] 0 M R [0]*M [0] 0 M A = set(range(N)) A set(range(N)) set range(N) range N lm, rm = 0, N lm 0 rm N for i in range(M):
    L[i], R[i] = map(int, input().split())
    lm = max(lm, L[i])
    rm = min(rm, R[i]) 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 lm = max(lm, L[i]) lm max(lm, L[i]) max lm L[i] L i rm = min(rm, R[i]) rm min(rm, R[i]) min rm R[i] R i if lm <= rm:
    print(rm-lm+1)
else:
    print(0) lm <= rm lm rm print(rm-lm+1) print rm-lm+1 rm-lm rm lm 1 print(0) print 0 A = set(range(N)) set(range(N)) A rm = min(rm, R[i]) min(rm, R[i]) rm N, M = map(int, input().split()) map(int, input().split()) N lm, rm = 0, N 0 lm M = map(int, input().split()) map(int, input().split()) M R = [0]*M, [0]*M [0]*M R L, R = [0]*M, [0]*M [0]*M L rm = 0, N N rm lm = max(lm, L[i]) max(lm, L[i]) lm
N, M = map(int, input().split())
L, R = [0]*M, [0]*M
A = set(range(N))
lm, rm = 0, N
for i in range(M):
    L[i], R[i] = map(int, input().split())
    lm = max(lm, L[i])
    rm = min(rm, R[i])
if lm <= rm:
    print(rm-lm+1)
else:
    print(0)