#!/usr/bin/env python3

n, m = list(map(int, input().split()))

li = [0] * (n + 1)

for _ in range(m):

    l, r = [int(x) - 1 for x in input().split()]

    li[0] += 1

    li[l] -= 1

    li[r + 1] += 1

    li[n] -= 1

for i in range(n):

    li[i + 1] += li[i]

print((sum(x <= 0 for x in li[:-1])))

n, m = list(map(int, input().split()))

ml, mr = 0, n

for i in range(m):

    l, r = [int(x) - 1 for x in input().split()]

    ml = max(ml, l)

    mr = min(mr, r)

print((max(0, mr - ml + 1)))

#!/usr/bin/env python3
n, m = list(map(int, input().split()))
li = [0] * (n + 1)
for _ in range(m):
    l, r = [int(x) - 1 for x in input().split()]
    li[0] += 1
    li[l] -= 1
    li[r + 1] += 1
    li[n] -= 1
for i in range(n):
    li[i + 1] += li[i]
print((sum(x <= 0 for x in li[:-1])))

n, m = list(map(int, input().split()))
ml, mr = 0, n
for i in range(m):
    l, r = [int(x) - 1 for x in input().split()]
    ml = max(ml, l)
    mr = min(mr, r)
print((max(0, mr - ml + 1)))

-#!/usr/bin/env python3 -li = [0] * (n + 1) -for _ in range(m): +ml, mr = 0, n +for i in range(m): -    li[0] += 1 -    li[l] -= 1 -    li[r + 1] += 1 -    li[n] -= 1 -for i in range(n): -    li[i + 1] += li[i] -print((sum(x <= 0 for x in li[:-1]))) +    ml = max(ml, l) +    mr = min(mr, r) +print((max(0, mr - ml + 1)))