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

lower = 0
upper = N+1
for _ in range(M):
    L, R = map(int, input().split())
    lower = max(lower, L)
    upper = min(upper, R+1)
c = upper - lower
if c <= 0:
    print(0)
else:
    print(c) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M lower = 0 lower 0 upper = N+1 upper N+1 N 1 for _ in range(M):
    L, R = map(int, input().split())
    lower = max(lower, L)
    upper = min(upper, R+1) _ range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R lower = max(lower, L) lower max(lower, L) max lower L upper = min(upper, R+1) upper min(upper, R+1) min upper R+1 R 1 c = upper - lower c upper - lower upper lower if c <= 0:
    print(0)
else:
    print(c) c <= 0 c 0 print(0) print 0 print(c) print c L, R = map(int, input().split()) map(int, input().split()) L M = map(int, input().split()) map(int, input().split()) M upper = min(upper, R+1) min(upper, R+1) upper lower = 0 0 lower c = upper - lower upper - lower c upper = N+1 N+1 upper lower = max(lower, L) max(lower, L) lower N, M = map(int, input().split()) map(int, input().split()) N R = map(int, input().split()) map(int, input().split()) R
N, M = map(int, input().split())

lower = 0
upper = N+1
for _ in range(M):
    L, R = map(int, input().split())
    lower = max(lower, L)
    upper = min(upper, R+1)
c = upper - lower
if c <= 0:
    print(0)
else:
    print(c)
