n, m = map(int, input().split())
k = [list(map(int, input().split())) for i in range(m)]
l, r = [list(i) for i in zip(*k)]
x = max(l)
y = min(r)
p = 0
for i in range(1, n + 1):
    if x <= i and i <= y:
        p += 1
print(p)

b5e6c41597629e1fcefa5f9b9b899a0926d960c4
<mask token>

<mask token>
for i in range(1, n + 1):
    if x <= i and i <= y:
        p += 1
print(p)

n, m = map(int, input().split())
k = [list(map(int, input().split())) for i in range(m)]
l, r = [list(i) for i in zip(*k)]
x = max(l)
y = min(r)
p = 0
for i in range(1, n + 1):
    if x <= i and i <= y:
        p += 1
print(p)
