import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
l_key = []
r_key = []
for i in range(m):
    l, r = map(int, input().split())
    l_key.append(l)
    r_key.append(r)

print(max(0, min(r_key) - max(l_key) + 1)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l_key = [] l_key [] r_key = [] r_key [] for i in range(m):
    l, r = map(int, input().split())
    l_key.append(l)
    r_key.append(r) i range(m) range m l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r l_key.append(l) l_key.append l_key append l r_key.append(r) r_key.append r_key append r print(max(0, min(r_key) - max(l_key) + 1)) print max(0, min(r_key) - max(l_key) + 1) max 0 min(r_key) - max(l_key) + 1 min(r_key) - max(l_key) min(r_key) min r_key max(l_key) max l_key 1 l_key = [] [] l_key r = map(int, input().split()) map(int, input().split()) r n, m = map(int, input().split()) map(int, input().split()) n l, r = map(int, input().split()) map(int, input().split()) l input = sys.stdin.readline sys.stdin.readline input r_key = [] [] r_key m = map(int, input().split()) map(int, input().split()) m
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
l_key = []
r_key = []
for i in range(m):
    l, r = map(int, input().split())
    l_key.append(l)
    r_key.append(r)

print(max(0, min(r_key) - max(l_key) + 1))
