# 2019-11-13 08:30:54(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

# import itertools

# from functools import reduce

# import operator as op

# from scipy.misc import comb # float

# import numpy as np 



def main():

    n, m = [int(x) for x in sys.stdin.readline().split()]



    l, r = [], []

    for _ in range(m):

        li, ri = [int(x) for x in sys.stdin.readline().split()]

        l.append(li)

        r.append(ri)

    

    print((min(r) - max(l) + 1 if min(r) >= max(l) else 0))







if __name__ == "__main__":

    main()

import sys



n, m, *lr = list(map(int, sys.stdin.read().split()))

lr = list(zip(*[iter(lr)] * 2))



def main():

    cnt = [0] * (n + 1)

    for l, r in lr:

        cnt[l-1] += 1

        cnt[r] -= 1

    

    for i in range(n):

        cnt[i+1] += cnt[i]

    

    res = 0

    for i in range(n):

        res += (cnt[i] == m) & 1

    

    return res



if __name__ == '__main__':

    ans = main()

    print(ans)
# 2019-11-13 08:30:54(JST)
import sys

# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]
    l, r = [], []
    for _ in range(m):
        li, ri = [int(x) for x in sys.stdin.readline().split()]
        l.append(li)
        r.append(ri)
    print((min(r) - max(l) + 1 if min(r) >= max(l) else 0))


if __name__ == "__main__":
    main()

import sys

n, m, *lr = list(map(int, sys.stdin.read().split()))
lr = list(zip(*[iter(lr)] * 2))


def main():
    cnt = [0] * (n + 1)
    for l, r in lr:
        cnt[l - 1] += 1
        cnt[r] -= 1
    for i in range(n):
        cnt[i + 1] += cnt[i]
    res = 0
    for i in range(n):
        res += (cnt[i] == m) & 1
    return res


if __name__ == "__main__":
    ans = main()
    print(ans)

-# 2019-11-13 08:30:54(JST) -# import collections -# import math -# from string import ascii_lowercase, ascii_uppercase, digits -# from bisect import bisect_left as bi_l, bisect_right as bi_r -# import itertools -# from functools import reduce -# import operator as op -# from scipy.misc import comb # float -# import numpy as np +n, m, *lr = list(map(int, sys.stdin.read().split())) +lr = list(zip(*[iter(lr)] * 2)) + + -    n, m = [int(x) for x in sys.stdin.readline().split()] -    l, r = [], [] -    for _ in range(m): -        li, ri = [int(x) for x in sys.stdin.readline().split()] -        l.append(li) -        r.append(ri) -    print((min(r) - max(l) + 1 if min(r) >= max(l) else 0)) +    cnt = [0] * (n + 1) +    for l, r in lr: +        cnt[l - 1] += 1 +        cnt[r] -= 1 +    for i in range(n): +        cnt[i + 1] += cnt[i] +    res = 0 +    for i in range(n): +        res += (cnt[i] == m) & 1 +    return res -    main() +    ans = main() +    print(ans)