n, m = map(int, input().split())
a = []
for i in range(m):
    a.append(input().split())
haba = a[0]
for i in a:
    if int(haba[0]) <= int(i[0]) <= int(haba[1]):
        haba[0] = i[0]
    elif int(haba[1]) < int(i[0]):
        print(0)
        exit()
    if int(haba[0]) <= int(i[1]) <= int(haba[1]):
        haba[1] = i[1]
    elif int(i[1]) < int(haba[0]):
        print(0)
        exit()
if n < int(haba[0]):
    ans = 0
elif int(haba[0]) <= n <= int(haba[1]):
    ans = n - int(haba[0]) + 1
else:
    ans = int(haba[1]) - int(haba[0]) + 1
print(ans) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = [] a [] for i in range(m):
    a.append(input().split()) i range(m) range m a.append(input().split()) a.append a append input().split() ().split () input split haba = a[0] haba a[0] a 0 for i in a:
    if int(haba[0]) <= int(i[0]) <= int(haba[1]):
        haba[0] = i[0]
    elif int(haba[1]) < int(i[0]):
        print(0)
        exit()
    if int(haba[0]) <= int(i[1]) <= int(haba[1]):
        haba[1] = i[1]
    elif int(i[1]) < int(haba[0]):
        print(0)
        exit() i a if int(haba[0]) <= int(i[0]) <= int(haba[1]):
        haba[0] = i[0]
    elif int(haba[1]) < int(i[0]):
        print(0)
        exit()
     int(haba[0]) <= int(i[0]) <= int(haba[1]) int(haba[0]) <= int(i[0]) int(haba[0]) int haba[0] haba 0 int(i[0]) int i[0] i 0 int(haba[1]) int haba[1] haba 1 haba[0] = i[0] haba[0] haba 0 i[0] i 0 elif int(haba[1]) < int(i[0]):
        print(0)
        exit()
     int(haba[1]) < int(i[0]) int(haba[1]) int haba[1] haba 1 int(i[0]) int i[0] i 0 print(0) print 0 exit() exit if int(haba[0]) <= int(i[1]) <= int(haba[1]):
        haba[1] = i[1]
    elif int(i[1]) < int(haba[0]):
        print(0)
        exit() int(haba[0]) <= int(i[1]) <= int(haba[1]) int(haba[0]) <= int(i[1]) int(haba[0]) int haba[0] haba 0 int(i[1]) int i[1] i 1 int(haba[1]) int haba[1] haba 1 haba[1] = i[1] haba[1] haba 1 i[1] i 1 elif int(i[1]) < int(haba[0]):
        print(0)
        exit() int(i[1]) < int(haba[0]) int(i[1]) int i[1] i 1 int(haba[0]) int haba[0] haba 0 print(0) print 0 exit() exit if n < int(haba[0]):
    ans = 0
elif int(haba[0]) <= n <= int(haba[1]):
    ans = n - int(haba[0]) + 1
else:
    ans = int(haba[1]) - int(haba[0]) + 1 n < int(haba[0]) n int(haba[0]) int haba[0] haba 0 ans = 0 ans 0 elif int(haba[0]) <= n <= int(haba[1]):
    ans = n - int(haba[0]) + 1 int(haba[0]) <= n <= int(haba[1]) int(haba[0]) <= n int(haba[0]) int haba[0] haba 0 n int(haba[1]) int haba[1] haba 1 ans = n - int(haba[0]) + 1 ans n - int(haba[0]) + 1 n - int(haba[0]) n int(haba[0]) int haba[0] haba 0 1 ans = int(haba[1]) - int(haba[0]) + 1 ans int(haba[1]) - int(haba[0]) + 1 int(haba[1]) - int(haba[0]) int(haba[1]) int haba[1] haba 1 int(haba[0]) int haba[0] haba 0 1 print(ans) print ans n, m = map(int, input().split()) map(int, input().split()) n ans = int(haba[1]) - int(haba[0]) + 1 int(haba[1]) - int(haba[0]) + 1 ans haba = a[0] a[0] haba ans = 0 0 ans ans = n - int(haba[0]) + 1 n - int(haba[0]) + 1 ans a = [] [] a m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
a = []
for i in range(m):
    a.append(input().split())
haba = a[0]
for i in a:
    if int(haba[0]) <= int(i[0]) <= int(haba[1]):
        haba[0] = i[0]
    elif int(haba[1]) < int(i[0]):
        print(0)
        exit()
    if int(haba[0]) <= int(i[1]) <= int(haba[1]):
        haba[1] = i[1]
    elif int(i[1]) < int(haba[0]):
        print(0)
        exit()
if n < int(haba[0]):
    ans = 0
elif int(haba[0]) <= n <= int(haba[1]):
    ans = n - int(haba[0]) + 1
else:
    ans = int(haba[1]) - int(haba[0]) + 1
print(ans)