N, M = map(int, input().split())
l, r = 1, N
for i in range(M):
    L, R = map(int, input().split())
    l, r = max(l, L), min(r, R)
if r - l >= 0:
    print(min(r - l + 1, N))
else:
    print(0) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M l, r = 1, N l 1 r N for i in range(M):
    L, R = map(int, input().split())
    l, r = max(l, L), min(r, R) i range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R l, r = max(l, L), min(r, R) l max(l, L) max l L r min(r, R) min r R if r - l >= 0:
    print(min(r - l + 1, N))
else:
    print(0) r - l >= 0 r - l r l 0 print(min(r - l + 1, N)) print min(r - l + 1, N) min r - l + 1 r - l r l 1 N print(0) print 0 r = max(l, L), min(r, R) min(r, R) r l, r = max(l, L), min(r, R) max(l, L) l r = 1, N N r l, r = 1, N 1 l N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M L, R = map(int, input().split()) map(int, input().split()) L R = map(int, input().split()) map(int, input().split()) R
N, M = map(int, input().split())
l, r = 1, N
for i in range(M):
    L, R = map(int, input().split())
    l, r = max(l, L), min(r, R)
if r - l >= 0:
    print(min(r - l + 1, N))
else:
    print(0)