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)
import sys



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

l, r = lr[::2], lr[1::2]



def main():

    ans = max(min(r) - max(l) + 1, 0)

    return ans



if __name__ == '__main__':

    ans = main()

    print(ans)
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)

import sys

n, m, *lr = list(map(int, sys.stdin.read().split()))
l, r = lr[::2], lr[1::2]


def main():
    ans = max(min(r) - max(l) + 1, 0)
    return ans


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

-lr = list(zip(*[iter(lr)] * 2)) +l, r = lr[::2], lr[1::2] -    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 +    ans = max(min(r) - max(l) + 1, 0) +    return ans