CodeEff/ECCO huggingface dataset:
# Original solution
n, m = list(map(int,input().split()))
arr = [0]*n
for i in range(m):
    l, r = list(map(int, input().split()))
    for j in range(l-1,r):
        arr[j]+=1
print((arr.count(m)))


# Optimized solution
n, m = list(map(int,input().split()))
arr = [1, n]
check = True
for i in range(m):
    l, r = list(map(int, input().split()))
    if l <= arr[0] and r>= arr[1]:
        continue
    elif l > arr[1] or r < arr[0]:
        check = False
    if arr[0] <= l and l <= arr[1]:
        arr[0] = l
    if arr[1] >= r and r >= arr[0]:
        arr[1] = r
if check:
    print((arr[1] - arr[0] + 1))
else:
    print((0))
# Original solution
n,m = list(map(int,input().split()))
lScope = []
rScope = []
ans = 0
for i in range(m):
    l,r = list(map(int,input().split()))
    lScope.append(l)
    rScope.append(r)
# k in keyScope[i] (i= 0~m) を確かめたい
for key in range(1,n+1):
    if max(lScope) <= key <= min(rScope):
        ans += 1
print(ans)

# Optimized solution
n,m = list(map(int,input().split()))
lScope = []
rScope = []
ans = 0
for i in range(m):
    l,r = list(map(int,input().split()))
    lScope.append(l)
    rScope.append(r)
# k in keyScope[i] (i= 0~m) を確かめたい
if min(rScope) >= max(lScope):
    print((min(rScope) - max(lScope) + 1))
else:
    print((0))
# Original solution
n,m=list(map(int,input().split()))
ans=[1 for i in range(n)]
for i in range(m):
	l,r=list(map(int,input().split()))
	for j in range(n):
		if ans[j]==1:
			if j<l-1 or j>r-1:
				ans[j]=0
print((ans.count(1)))

# Optimized solution
n,m=list(map(int,input().split()))
lmax,rmin=0,n
for i in range(m):
	l,r=list(map(int,input().split()))
	if l>lmax:
		lmax=l
	if r<rmin:
		rmin=r
if rmin-lmax<0:
	print((0))
else:
	print((rmin-lmax+1))
# Original solution
N,M = list(map(int,input().split()))
cards = [True]*N

for g in range(M):
  L,R = list(map(int,input().split()))
  for i in range(L-1):
    cards[i] = False
  for i in range(R,N):
    cards[i] = False
print((cards.count(True)))

# Optimized solution
N,M = list(map(int,input().split()))
maL = 0
miR = N
for g in range(M):
  L,R = list(map(int,input().split()))
  maL = max(maL,L)
  miR = min(miR,R)
if maL <= miR:
  print((miR-maL+1))
else:
  print((0))
# Original solution
N, M = list(map(int, input().split()))
List = [list(map(int, input().split())) for _ in range(M)]

ones = [1]*N

for i in range(M):
    ones[List[i][1]:]=[0]*(N-List[i][1])
    ones[:List[i][0]-1]=[0]*(List[i][0]-1)
    
print((sum(ones)))

# Optimized solution
N, M = list(map(int, input().split()))
List = [list(map(int, input().split())) for _ in range(M)]

left = 1
right = N
for i in range(M):
    if left<List[i][0]:
        left = List[i][0]
    if List[i][1]<right:
        right = List[i][1]

if right<left:
    print((0))
else:
    print((right-left+1))
# Original solution
N, M = list(map(int, input().split()))

if M == 1:
    l1, r1 = list(map(int, input().split()))
    print((r1 - l1 + 1))
else:
    C = 0
    
    l1, r1 = list(map(int, input().split()))
    for _ in range(M - 1):
        l2, r2 = list(map(int, input().split()))

        A = list(range(l1, r1 + 1))
        B = list(range(l2, r2 + 1))

        C = set(A) & set(B)
    print((len(C)))

# Optimized solution
N, M = list(map(int, input().split()))
left= []
right = []
for _ in range(M):
    L, R = list(map(int, input().split()))
    left.append(L)
    right.append(R)

min_right = min(right)
max_left = max(left)
if min_right < max_left:
    print((0))
else:
    print((min_right - max_left + 1))
# Original solution
card_num, gate_num = list(map(int, input().split()))

s, t = list(map(int, input().split()))
all_set = set(range(s, t+1))
for _ in range(gate_num-1):
    s, t = list(map(int, input().split()))
    all_set = all_set.intersection(set(range(s, t+1)))

print((len(all_set)))


# Optimized solution
card_num, gate_num = list(map(int, input().split()))

ans_start, ans_end = list(map(int, input().split()))
for _ in range(gate_num-1):
    s, e = list(map(int, input().split()))
    if e < ans_start or ans_end < s:
        print((0))
        exit()
    elif s < ans_start and ans_start < e < ans_end:
        ans_end = e
    elif ans_start < s < ans_end and ans_end < e:
        ans_start = s
    elif ans_start == e:
        ans_end = e
    elif ans_end == s:
        ans_start = s

print((ans_end - ans_start + 1))
# Original solution
n, m = list(map(int, input().split()))
lis = [1]*(n+2)
lis[0] = 0
lis[-1] = 0

for k in range(m):
  i, j = list(map(int, input().split()))
  lis[:i] = [0]*(i)
  lis[j+1:] = [0]*(n - j + 2)
  
print((sum(lis)))

# Optimized solution
n, m = list(map(int, input().split()))
i = 0
j = n + 1

for k in range(m):
  ti, tj = list(map(int, input().split()))
  if ti > i:
    i = ti
  if tj < j:
    j = tj

if j == 0 and i == 0:
  print((0))
else:
  print((max(j - i + 1, 0)))
# Original solution
N,M=list(map(int, input().split()))

L,R=list(map(int, input().split()))
s=[i for i in range(L,R+1)]
t=[]
for i in range(M-1):
    L,R=list(map(int, input().split()))
    t=[j for j in range(L,R+1)]
    s = set(s) & set(t)
    #print(s)

print((len(s)))

# Optimized solution
N,M=list(map(int, input().split()))

L=[]
R=[]

for i in range(M):
    a,b=list(map(int, input().split()))
    L.append(a)
    R.append(b)

ans=min(R)-max(L)+1
print(("0" if ans<0 else ans))
# Original solution
N,M =list(map(int,input().split()))
L = [0]*M
R = [0]*M
ans = int(0)

for i in range(M):
    L[i],R[i] = list(map(int,input().split()))


for i in range(N):
    j = int(0)
    while (R[j]>=i+1>=L[j]) :
        j += 1
        if j==M:
            ans +=1
            break


print(ans)


# Optimized solution
N,M =list(map(int,input().split()))
L = [0]*M
R = [0]*M
ans = int(0)

for i in range(M):
    L[i],R[i] = list(map(int,input().split()))

a1 = max(L)
a2 = min(R)

ans = a2-a1+1

if ans<0 : ans = int(0)

print((int(ans)))
# Original solution
n, m = list(map(int,input().split()))
ans = [0]*n

for _ in range(m):
  l, r = list(map(int,input().split()))
  for i in range(l-1, r):
    ans[i] += 1
print((ans.count(m)))

# Optimized solution
n, m = list(map(int,input().split()))
maxL, minR = 1, n
L = []
R = []
for i in range(m):
  l, r = list(map(int,input().split()))
  maxL = max(maxL, l)
  minR = min(minR, r)

ans = minR - maxL + 1
print((max(ans, 0)))
# Original solution
N, M = list(map(int, input().split()))
count = [0]*N
for i in range(M):
    L, R = list(map(int, input().split()))
    for i in range(L, R+1):
        count[i-1] += 1
ans = 0
for i in count:
    if i == M:
        ans += 1
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
maxL = 0
minR = float('inf')
for i in range(M):
    L, R = list(map(int, input().split()))
    maxL = max(maxL, L)
    minR = min(minR, R)
if minR - maxL >= 0:
    print((minR - maxL + 1))
else:
    print((0))
# Original solution
N, M = list(map(int,input().split()))

LR = []

for i in range(M):
    LR.append(list(map(int,input().split())))

cnt = 0

for i in range(1,N+1):
    for lr in LR:
        if i < lr[0] or i > lr[1]:
            break
    else:
        cnt += 1

print(cnt)
    

# Optimized solution
N, M = list(map(int,input().split()))

Nmin = 1
Nmax = N

for i in range(M):
    L, R = list(map(int,input().split()))
    Nmin = max(L,Nmin)
    Nmax = min(R,Nmax)

print((max(Nmax-Nmin+1,0)))
# Original solution
n, m = list(map(int, input().split()))
L, R = [], []
for _ in range(m):
    li, ri = list(map(int, input().split()))
    L.append(li)
    R.append(ri)

ans = 0

for i in range(1, n+1):
    flag = True
    for li, ri in zip(L, R):
        if not (i >= li and i <= ri):
            flag = False
            break
    if flag:
        ans += 1

print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
L, R = [], []
for _ in range(m):
    li, ri = list(map(int, input().split()))
    L.append(li)
    R.append(ri)

# ans = 0

# for i in range(1, n+1):
#     flag = True
#     for li, ri in zip(L, R):
#         if not (i >= li and i <= ri):
#             flag = False
#             break
#     if flag:
#         ans += 1

# print(ans)

ans = min(min(R), n) - min(max(L), n) +1
if ans < 0:
        ans = 0
print(ans)
# Original solution
n, m = list(map(int, input().split()))
l, r = list(map(int, input().split()))
S = set(range(l, r + 1))
for i in range(m - 1):
	l, r = list(map(int, input().split()))
	S &= set(range(l, r + 1))
print((len(S)))

# Optimized solution
n, m = list(map(int, input().split()))
maxl, minr = list(map(int, input().split()))
for i in range(m - 1):
	l, r = list(map(int, input().split()))
	maxl = max(maxl, l)
	minr = min(minr, r)
print((max(0, minr - maxl + 1)))
# Original solution
N,M = list(map(int,input().split()))
count = 0
for i in range(M):
    a,b = list(map(int,input().split()))
    if count == 0:
        set = {i for i in range(a,b+1)}
        count = 1
    else:
        set = set & {i for i in range(a,b+1)}
print((len(set)))

# Optimized solution
N,M = list(map(int,input().split()))
count = 0
for i in range(M):
    a,b = list(map(int,input().split()))
    if count == 0:
        L = a
        R = b
        count = 1
    else:
        if L < a:
            L =a
            if L>R:
                break
        if R > b:
            R = b
            if R < L:
                break
if M == i+1:
    print((R-L+1))
else:
    print((0))
# Original solution
n , m = list(map(int,input().split()))
a = [1] * n
ans = 0

for i in range(m):
    l , r = list(map(int,input().split()))
    for j in range(n):
        if l > j + 1 or j + 1 > r:
            a[j] = 0
            
for i in range(n):
    ans += a[i]
    
print(ans)        

# Optimized solution
n , m = list(map(int,input().split()))
a , b = 1 , 100000

for i in range(m):
    l , r = list(map(int,input().split()))
    if a <= l:
        a = l
    if b >= r:
        b = r
        
c = b - a + 1
if c > 0:
    print(c)
else:
    print((0))
# Original solution
import collections
n,m = list(map(int,input().split()))
r = []
ans = 0
for i in range(m):
    ll,rr = list(map(int,input().split()))
    for j in range(ll-1,rr):
        r.append(j)
cnt = collections.Counter(r)
for i in list(cnt.values()):
    if i == m:
        ans += 1
print(ans)

# Optimized solution
import collections
n,m = list(map(int,input().split()))
r = []
l = []
for i in range(m):
    ll,rr = list(map(int,input().split()))
    r.append(rr)
    l.append(ll)
ans = min(r) - max(l) +1
if ans > 0:
    print(ans)
else :
    print((0))
# Original solution

N,M=list(map(int,input().split()))

result=0
LR=[]
for i in range(M):
        LR.append(input().split())


for i in range(N+1):#0からNまで
    counter=0
    flag=False
    if flag:
        break
    for j in LR:

        L=int(j[0])
        R=int(j[1])
        if i<L or R<i:
            flag=True
            break
        if L<=i and i<=R:
            counter+=1

    if counter==M:
        result+=1
print(result)


# Optimized solution

N,M=list(map(int,input().split()))#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=1
Rmax=100000
for j in LR:

    L=int(j[0])
    R=int(j[1])

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)
# Original solution
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]
cnt = [0]*n
for i in range(m):
    for j in range(lr[i][0]-1, lr[i][1]):
        cnt[j] += 1
ans = sum(i==m for i in cnt)
print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
left = 0
right = n+1
for i in range(m):
    l, r = list(map(int, input().split()))
    left = max(left, l)
    right = min(right, r)
ans = 0
for i in range(left-1, right):
    ans += 1
print(ans)
# Original solution
n, m = list(map(int, input().split()))
cards = {i: False for i in range(1, n+1)}

for _ in range(m):
    l, r = list(map(int, input().split()))
    for i in cards:
        if i < l or i > r:
            cards[i] = True

sum = 0
for v in list(cards.values()):
    if not v:
        sum += 1

print(sum)

# Optimized solution
n, m = list(map(int, input().split()))
max_l = 1
min_r = n 

for _ in range(m):
    l, r = list(map(int, input().split()))
    max_l = max(max_l, l)
    min_r = min(min_r, r)

ans = max(min_r - max_l + 1, 0)
print(ans)
# Original solution
N,M = list(map(int,input().split()))

key = [0]*N
x = [list(map(int,input().split())) for i in range(M)]

for i in range(M):
	for j in range(x[i][0],x[i][1]+1):
		key[j-1] += 1

count = 0
for k in range(N):
	if key[k] == M:
		count += 1

print(count)

# Optimized solution
N,M = list(map(int,input().split()))
X = [list(map(int,input().split())) for i in range(M)]

keymax = 10**6
keymin = 0
for i in range(M):
	if X[i][0] > keymin:
		keymin = X[i][0]
	if X[i][1] < keymax:
		keymax = X[i][1]

if keymax >= keymin:
	print((keymax-keymin+1))
else:
	print("0")
# Original solution
N, M = list(map(int, input().split()))
X = set(range(1,N+1))
for i in range(M):
    L, R = list(map(int, input().split()))
    Y = set(range(L,R+1))
    X = X & Y
print((len(X)))


# Optimized solution
N, M = list(map(int, input().split()))

min, max = list(map(int, input().split()))

for i in range(1, M):
    L, R = list(map(int, input().split()))
    if L > max or R < min:
        print((0))
        exit()
    elif min < L <= max:
        min = L
    elif min <= R < max:
        max = R
print((max-min+1))
# Original solution
N, M = list(map(int, input().split()))

gates = []
for i in range(M):
    gates.append(tuple(map(int, input().split())))


s = set(range(gates[0][0], gates[0][-1] + 1)) 
for g in gates[1:]:
    tmp_s = set(range(g[0], g[-1] + 1))
    s = s.intersection(tmp_s)

print((len(s)))

# Optimized solution
N, M = list(map(int, input().split()))

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

l_max = max(L)
r_min = min(R)

if l_max <= r_min:
    print((r_min - l_max + 1))
else:
    print((0))
# Original solution
n, m = list(map(int, input().split()))
a, b = list(map(int, input().split()))
k = set(range(a, b+1))
for i in range(m - 1):
    a, b = list(map(int, input().split()))
    k = k.intersection(set(range(a, b+1)))
print((len(k)))

# Optimized solution
n, m = list(map(int, input().split()))
L = set()
R = set()
for i in range(m):
    l, r = list(map(int, input().split()))
    L.add(l)
    R.add(r)
if min(R) >=  max(L):
    num = min(R) - max(L) + 1
else:
    num = 0
print(num)
# Original solution
def main():
    N, M = list(map(int, input().split()))
    lr = [list(map(int, list(input().split()))) for i in range(M)]
    # N, M = 4, 2
    # lr = [[1, 3], [2, 4]]
    all_set = set(range(1, N + 1))
    for line in lr:
        all_set = all_set & set(range(line[0], line[1] + 1))
    print((len(all_set)))


if __name__ == '__main__':
    main()

# Optimized solution
def main():
    N, M = list(map(int, input().split()))
    lr = [list(map(int, list(input().split()))) for i in range(M)]
    # N, M = 4, 2
    # lr = [[1, 1], [3, 4]]
    ll = []
    rl = []
    for line in lr:
        ll.append(line[0])
        rl.append(line[1])
    diff = min(rl) - max(ll)
    if diff < 0:
        print((0))
        return
    print((diff + 1))


if __name__ == '__main__':
    main()
# Original solution
N, M = list(map(int, input().split()))

result = [0]*N

for m in range(M):
    L, R = list(map(int, input().split()))
    for i in range(L, R+1):
        result[i-1] += 1

counter = 0
for i in result:
    if i == M:
        counter += 1
print(counter)

# Optimized solution
N, M = list(map(int, input().split()))

for m in range(M):
    L, R = list(map(int, input().split()))
    if m==0:
        l = L
        r = R
    else:
        if l<L:
            l = L
        if R<r:
            r = R

print((len(list(range(l,r+1)))))
# Original solution
N, M = list(map(int, input().split()))
L, R = [0]*M, [0]*M
A = set(range(N))
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))
    A = A & set(range(L[i]-1, R[i]))
print((len(A)))

# Optimized solution
N, M = list(map(int, input().split()))
L, R = [0]*M, [0]*M
A = set(range(N))
lm, rm = 0, N
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))
    lm = max(lm, L[i])
    rm = min(rm, R[i])
if lm <= rm:
    print((rm-lm+1))
else:
    print((0))
# Original solution
N,M=list(map(int,input().split()))
ans=set([i for i in range(1,N+1)])
for i in range(M):
    a,b=list(map(int,input().split()))
    tmp=set([i for i in range(a,b+1)])
    ans &=tmp
print((len(ans)))

# Optimized solution
N,M=list(map(int,input().split()))
s=1
m=N
for i in range(M):
    a,b=list(map(int,input().split()))
    if s<a:
        s=a
    if m>b:
        m=b
    #ans &=tmp
ans=m-s+1
if ans>0:
    print(ans)
else:
    print((0))
# Original solution
N, M = list(map(int, input().strip().split()))

set_ = set()
for m in range(M):
    s, e = list(map(int, input().strip().split()))
    tmp = set()
    for i in range(s, e+1):
        tmp.add(i)

    if m == 0:
        set_ = tmp
    else:
        set_ = set_ & tmp

print((len(set_)))


# Optimized solution
N, M = list(map(int, input().strip().split()))

s_list = list()
e_list = list()

for m in range(M):
    s, e = list(map(int, input().strip().split()))
    s_list.append(s)
    e_list.append(e)

s_max = max(s_list)
e_min = min(e_list)

if s_max > e_min:
    print((0))
else:
    print((e_min-s_max+1))
# Original solution
n,m=list(map(int,input().split()))
s=[0]*n
for _ in range(m):
    b,c=list(map(int,input().split()))
    for i in range(b-1,c):
        s[i]+=1
print((s.count(m)))

# Optimized solution
n,m=list(map(int,input().split()))
s=[0]*n
max_=1
min_=n
for _ in range(m):
    b,c=list(map(int,input().split()))
    if b>max_:
        max_=b
    if c<min_:
        min_=c
if min_<max_:
  print('0')
else:
  print((min_-max_+1))
# Original solution
n,m = list(map(int,input().split()))
li=[list([int(x)+1 for x in input().split()]) for _ in range(m)]
s=set(range(li[0][0],li[0][1]+1))
for i in li:
  s = s & set(range(i[0],i[1]+1))
print((len(s)))

# Optimized solution
n,m = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(m)]
l = s[0][0]
r = s[0][1]
for i,j in s:
  if i>l:l=i
  if j<r:r=j
print((max(0,r-l+1)))
# Original solution
import itertools
import math
import fractions
import functools
import copy
n, m = list(map(int, input().split()))
lr = []
for i in range(m):
    l, r = list(map(int, input().split()))
    lr.append([l,r])

result = list(range(lr[0][0],lr[0][1]+1))

for i in range(len(result)):
    for pair in lr:
        if not(pair[0] <= result[i] and pair[1] >= result[i]):
            result[i] = -1

print((len(result)-result.count(-1)))



# Optimized solution
import itertools
import math
import fractions
import functools
import copy
n, m = list(map(int, input().split()))
lr = []
for i in range(m):
    l, r = list(map(int, input().split()))
    lr.append([l,r])

result = list(range(lr[0][0],lr[0][1]+1))


maximum = lr[0][1]
minimum = lr[0][0]
for i in range(len(lr)):
    maximum = min(maximum,lr[i][1])
    minimum = max(minimum,lr[i][0])

if maximum < minimum:
    print((0))
else:
    print((maximum-minimum+1))
# Original solution
n,m = list(map(int,input().split()))
li = []
counter = 0
for i in range(m):
    l,r = list(map(int,input().split()))
    for j in range(l,r+1):
        li.append(j)
import collections
c = collections.Counter(li)
for k in list(c.values()):
    if k == m:
        counter += 1
print(counter)


# Optimized solution
n,m = list(map(int,input().split()))
l,r = list(map(int,input().split()))
counter = 0
for i in range(m-1):
    l1,r1 = list(map(int,input().split()))
    if l < l1:
        l = l1
    if r > r1:
        r = r1
if r < l:
    print((0))
else:
    print((r-l+1))
# Original solution
# coding: utf-8
# Your code here!

N, M = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(M)]
L = [li[j][0] for j in range(M)]
R = [li[k][1] for k in range(M)]
ctr = 0

for i in range(1, N + 1):
    if i >= max(L) and i <= min(R):
        ctr += 1
print(ctr)

# Optimized solution
# coding: utf-8
# Your code here!

N, M = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(M)]
L = [li[j][0] for j in range(M)]
R = [li[k][1] for k in range(M)]
ctr = 0

if min(R) - max(L) >= 0:
    print((min(R) - max(L) + 1))
else:
    print((0))
# Original solution
# coding: utf-8
# Your code here!
from itertools import chain
from collections import Counter

N, M = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(M)]
arr = [[j for j in range(li[k][0], li[k][1] + 1)] for k in range(M)]
set_arr = list(chain.from_iterable(arr))
arr_duplicate = [l for l in list(Counter(set_arr).values()) if l == M]
print((len(arr_duplicate)))


# Optimized solution
# coding: utf-8
# Your code here!

N, M = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(M)]
L = [li[j][0] for j in range(M)]
R = [li[k][1] for k in range(M)]
ctr = 0

if min(R) - max(L) >= 0:
    print((min(R) - max(L) + 1))
else:
    print((0))
# Original solution
N, M = list(map(int, input().split()))
LR = []
for _ in range(M):
    L, R = list(map(int, input().split()))
    LR.append({i for i in range(L, R + 1)})

x = LR[0]
for y in LR:
    x &= y
print((len(x)))

# Optimized solution
N, M = list(map(int, input().split()))
L, R = [None] * M, [None] * M
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))

l = max(L)
r = min(R)
ans = r - l + 1
if ans < 0:
    ans = 0
print(ans)
# Original solution
n, m = list(map(int, input().split()))
ids = [0 for _ in range(n)]
for i in range(m):
  l, r = list(map(int, input().split()))
  for j in range(l-1, r):
    ids[j] += 1

ans = 0
for tmp_id in ids:
  if tmp_id == m:
    ans += 1
print(ans)  

# Optimized solution
n, m = list(map(int, input().split()))

l_tmp = 0
r_tmp = n+1
for i in range(m):
  l, r = list(map(int, input().split()))
  l_tmp = l if l > l_tmp else l_tmp
  r_tmp = r if r < r_tmp else r_tmp

if r_tmp-l_tmp >= 0:
  print((r_tmp-l_tmp+1))
else:
  print((0))
# Original solution
n,m = list(map(int,input().split()))
lr = [list(map(int,input().split())) for i in range(m)]

wildcard = set(range(lr[0][0],lr[0][1]+1))
for i in range(1,len(lr)):
    wildcard &= set(range(lr[i][0],lr[i][1]+1))

ans = len(wildcard)
print(ans)


# Optimized solution
n,m = list(map(int,input().split()))
lr = [list(map(int,input().split())) for i in range(m)]

lp = 1
rp = n

for i in range(m):
    if lp < lr[i][0]:
        lp = lr[i][0]
    if rp > lr[i][1]:
        rp = lr[i][1]
else:
    if rp - lp < 0:
        ans = 0
    else:
        ans = rp-lp+1

print(ans)
# Original solution
L,M=list(map(int,input().split()))
MAX=0
MIN=L
for i in range(M):
  A,B=list(map(int,input().split()))
  MAX=max(MAX,A)
  MIN=min(MIN,B)

print((max(0,MIN-MAX+1)))

# Optimized solution
L,M=list(map(int,input().split()))
MAX=0
MIN=10**5
for i in range(M):
  A,B=list(map(int,input().split()))
  MAX=max(MAX,A)
  MIN=min(MIN,B)

print((max(0,MIN-MAX+1)))
# Original solution
#36
N,M = list(map(int,input().split()))
li = []
ri = []
x = []
y = [i for i in range(1,N+1)]
cou = 0
for i in range(M):
    L,R = list(map(int,input().split()))
    for i in y:
        if L<=i and R>=i:
            x.append(i)
    y = x
    x = []
          
cou = len(y)
print(cou)
        
    

# Optimized solution
#36
N,M = list(map(int,input().split()))
li = []
ri = []
num = 0


for i in range(M):
    L,R = list(map(int,input().split()))
    li.append(L)
    ri.append(R)
L = max(li)
R = min(ri)
num = R-L+1
if num <0:
    num= 0
    
print(num)
# Original solution
N,M = list(map(int,input().split()))
a,b=list(map(int,input().split()))

l_=[int(n) for n in range(a,b+1)]

for i in range(M-1):
  c,d=list(map(int,input().split()))
  l__=[n for n in range(c,d+1)]
  l_=list(set(l_)&set(l__))
  
print((len(l_)))

# Optimized solution
n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
L=[]
R=[]
for i in range(m):
  L.append(l[i][0])
  R.append(l[i][1])
print((max(min(R)-max(L)+1,0)))