N, M = map(int,input().split())
L = []
R = []
for i in range(M):
    l, r = input().split()
    L.append(int(l))
    R.append(int(r))

if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0) N, M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L = [] L [] R = [] R [] for i in range(M):
    l, r = input().split()
    L.append(int(l))
    R.append(int(r)) i range(M) range M l, r = input().split() l input().split() ().split () input split r L.append(int(l)) L.append L append int(l) int l R.append(int(r)) R.append R append int(r) int r if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0) max(L) <= min(R) max(L) max L min(R) min R print(min(R) - max(L) + 1) print min(R) - max(L) + 1 min(R) - max(L) min(R) min R max(L) max L 1 print(0) print 0 l, r = input().split() input().split() l r = input().split() input().split() r N, M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M L = [] [] L R = [] [] R
N, M = map(int,input().split())
L = []
R = []
for i in range(M):
    l, r = input().split()
    L.append(int(l))
    R.append(int(r))

if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0)