import sys



def main():

    sinputl = sys.stdin.readline



    num_card, num_gate = [int(x) for x in sinputl().split()]

    input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]



    card = [1, num_card]



    for gate in input:

        card[0] = max(card[0], gate[0])

        card[1] = min(card[1], gate[1])



    print((max(card[1] - card[0] + 1, 0)))





if __name__ == "__main__":

    main()

import sys

     

def main():

    sinputl = sys.stdin.readline



    num_card, num_gate = [int(x) for x in sinputl().split()]

    input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]

   

    under_limit = [x[0] for x in input]

    over_limit = [x[1] for x in input]

     

    print((max(min(over_limit) - max(under_limit) + 1, 0)))

     

     

if __name__ == "__main__":

    main()
import sys


def main():
    sinputl = sys.stdin.readline
    num_card, num_gate = [int(x) for x in sinputl().split()]
    input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]
    card = [1, num_card]
    for gate in input:
        card[0] = max(card[0], gate[0])
        card[1] = min(card[1], gate[1])
    print((max(card[1] - card[0] + 1, 0)))


if __name__ == "__main__":
    main()

import sys


def main():
    sinputl = sys.stdin.readline
    num_card, num_gate = [int(x) for x in sinputl().split()]
    input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]
    under_limit = [x[0] for x in input]
    over_limit = [x[1] for x in input]
    print((max(min(over_limit) - max(under_limit) + 1, 0)))


if __name__ == "__main__":
    main()

-    card = [1, num_card] -    for gate in input: -        card[0] = max(card[0], gate[0]) -        card[1] = min(card[1], gate[1]) -    print((max(card[1] - card[0] + 1, 0))) +    under_limit = [x[0] for x in input] +    over_limit = [x[1] for x in input] +    print((max(min(over_limit) - max(under_limit) + 1, 0)))