



def main():

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



    A = []

    B = []



    for _ in range(m):

        a, b = list(map(int, input().split()))

        A.append(a)

        B.append(b)



         

    l = max(A)

    r = min(B)

    #print(l, r)



    if r >= l:

        return r - l + 1

    else:

        return 0



if __name__ == "__main__":

    print((main()))







"""

for i in range(1, n + 1):

        for j in range(m):

            if gate[j][0] <= i and i <= gate[j][1]:

                if j == len(gate) - 1:

                    result += 1

                continue

            else:

                break

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

# L = []

# R = []



l_max = 0

r_min = 10 ** 6

for _ in range(m):

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

    if l_max < l:

        l_max = l

    if r < r_min:

        r_min = r

if l_max <= r_min:

    print((r_min - l_max + 1))

else:

    print((0))
def main():
    n, m = list(map(int, input().split()))
    A = []
    B = []
    for _ in range(m):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    l = max(A)
    r = min(B)
    # print(l, r)
    if r >= l:
        return r - l + 1
    else:
        return 0


if __name__ == "__main__":
    print((main()))
"""
for i in range(1, n + 1):
        for j in range(m):
            if gate[j][0] <= i and i <= gate[j][1]:
                if j == len(gate) - 1:
                    result += 1
                continue
            else:
                break
"""

n, m = list(map(int, input().split()))
# L = []
# R = []
l_max = 0
r_min = 10**6
for _ in range(m):
    l, r = list(map(int, input().split()))
    if l_max < l:
        l_max = l
    if r < r_min:
        r_min = r
if l_max <= r_min:
    print((r_min - l_max + 1))
else:
    print((0))

-def main(): -    n, m = list(map(int, input().split())) -    A = [] -    B = [] -    for _ in range(m): -        a, b = list(map(int, input().split())) -        A.append(a) -        B.append(b) -    l = max(A) -    r = min(B) -    # print(l, r) -    if r >= l: -        return r - l + 1 -    else: -        return 0 - - -if __name__ == "__main__": -    print((main())) -""" -for i in range(1, n + 1): -        for j in range(m): -            if gate[j][0] <= i and i <= gate[j][1]: -                if j == len(gate) - 1: -                    result += 1 -                continue -            else: -                break -""" +n, m = list(map(int, input().split())) +# L = [] +# R = [] +l_max = 0 +r_min = 10**6 +for _ in range(m): +    l, r = list(map(int, input().split())) +    if l_max < l: +        l_max = l +    if r < r_min: +        r_min = r +if l_max <= r_min: +    print((r_min - l_max + 1)) +else: +    print((0))