#!/usr/bin/env python3

# -*- coding: utf-8 -*-



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

L = []

R = []

for i in range(M):

    l, r, = list(map(int, input().split()))

    L.append(l)

    R.append(r)

max_l = 0

min_r = N

for i in range(M):

    if max_l < L[i]:

        max_l = L[i]

    if min_r > R[i]:

        min_r = R[i]

if max_l > min_r:

    print((0))

else:

    print((min_r - max_l + 1))

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



max_left = 0

min_right = n

for _ in range(m):

    l_tmp, r_tmp = list(map(int, input().strip().split()))

    if max_left < l_tmp:

        max_left = l_tmp

    if r_tmp < min_right:

        min_right = r_tmp



if min_right < max_left:

    print((0))

else:

    print((min_right - max_left + 1))

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, M = list(map(int, input().split()))
L = []
R = []
for i in range(M):
    (
        l,
        r,
    ) = list(map(int, input().split()))
    L.append(l)
    R.append(r)
max_l = 0
min_r = N
for i in range(M):
    if max_l < L[i]:
        max_l = L[i]
    if min_r > R[i]:
        min_r = R[i]
if max_l > min_r:
    print((0))
else:
    print((min_r - max_l + 1))

n, m = list(map(int, input().strip().split()))
max_left = 0
min_right = n
for _ in range(m):
    l_tmp, r_tmp = list(map(int, input().strip().split()))
    if max_left < l_tmp:
        max_left = l_tmp
    if r_tmp < min_right:
        min_right = r_tmp
if min_right < max_left:
    print((0))
else:
    print((min_right - max_left + 1))

-#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -N, M = list(map(int, input().split())) -L = [] -R = [] -for i in range(M): -    ( -        l, -        r, -    ) = list(map(int, input().split())) -    L.append(l) -    R.append(r) -max_l = 0 -min_r = N -for i in range(M): -    if max_l < L[i]: -        max_l = L[i] -    if min_r > R[i]: -        min_r = R[i] -if max_l > min_r: +n, m = list(map(int, input().strip().split())) +max_left = 0 +min_right = n +for _ in range(m): +    l_tmp, r_tmp = list(map(int, input().strip().split())) +    if max_left < l_tmp: +        max_left = l_tmp +    if r_tmp < min_right: +        min_right = r_tmp +if min_right < max_left: -    print((min_r - max_l + 1)) +    print((min_right - max_left + 1))