CodeEff/ECCO huggingface dataset:
# Original solution
# -- coding:utf-8 --
n,m = list(map(int,input().split()))
lr = [list(map(int,input().split())) for ii in range(m)]
L = [lr[jj][0] for jj in range(m) ]
R = [lr[jj][1] for jj in range(m) ]

count = 0

for nn in range(1,n+1):
    check = [0]*m
    for kk in range(m):
        if nn >= L[kk] and nn <= R[kk]:
            check[kk] = 1
        if sum(check) == m:
            count += 1

print(count)


# Optimized solution
# -- coding:utf-8 --
n,m = list(map(int,input().split()))
lr = [list(map(int,input().split())) for ii in range(m)]
L = [lr[jj][0] for jj in range(m) ]
R = [lr[jj][1] for jj in range(m) ]

if min(R)-max(L) < 0:
    print((0))
else:
    print((min(R)-max(L)+1))
# Original solution
N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
ans = set(range(1, N + 1))
for lr in LR:
  ans = ans & set(range(lr[0], lr[1] + 1))
  
print((len(ans)))

# Optimized solution
N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
l = 0
r = 100001
for lr in LR:
  l = max(lr[0], l)
  r = min(r, lr[1])
  
print((r - l + 1 if r - l >= 0 else 0))
# Original solution
N, M = list(map(int, input().split()))
LRs = None
for i in range(M):
	l, r = list(map(int, input().split()))
	if(LRs is None):
		LRs = set(range(l, r+1))
	else:
		LRs = LRs.intersection(set(range(l, r+1)))
print((str(len(LRs))))

# Optimized solution
N, M = list(map(int, input().split()))
l_max = 0
r_min = 10**5+1
for i in range(M):
	l, r = list(map(int, input().split()))
	l_max = max(l, l_max)
	r_min = min(r, r_min)
if(l_max <= r_min):
	print((str(r_min - l_max + 1)))
else:
	print("0")
# Original solution
# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

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

#idカードの生成
    
for i in range(1,N+1):
    if max(l) <= i and i <= min(r):
        count += 1

print(count)

# Optimized solution
# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

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

#idカードの生成
    
ml = max(l)
mr = min(r)

for i in range(1,N+1):
    if  ml <= i and i <= mr:
        count += 1

print(count)
# Original solution
n,m = list(map(int,input().split()))

l = [0]*100000
r = [0]*100000

for i in range(0,m):
    l[i],r[i] = list(map(int,input().split()))

count = 0
num = 0

for key in range(1,n + 1):#鍵の番号
    for i in range(0,m):#
        if(key < l[i]):
            break
        if(key >= l[i] and key <= r[i]):
            count += 1
    if(count == m):
        num += 1
    count = 0
        
print(num)
        
    


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

l = [0]*m
r = [0]*m
b = [0]*(n + 2)

count = 0

for i in range(0,m):
    l[i],r[i] = list(map(int,input().split()))

l_max = max(l)
r_min = min(r)

for i in range(1,n+1):
        if(i >= l_max and i <= r_min ):
                count += 1
        
print(count)
# Original solution
n,m = list(map(int,input().split()))
LR = [[int(i) for i in input().split()] for i in range(m)]
ans = set(range(1,n+1))
for i in range(m):
    ans = ans & set(range(LR[i][0],LR[i][1]+1))
print((len(ans)))


# Optimized solution
n,m = list(map(int,input().split()))
p,q = 1,n
for i in range(m):
    l,r = list(map(int,input().split()))
    p = max(p,l)
    q = min(q,r)
if q>=p:
    print((q-p+1))
else:
    print((0))
# Original solution
n,m = list(map(int,input().split()))

for i in range(m):
    
    l,r = list(map(int,input().split()))

    lst = [x for x in range(l,r+1)]
    if i == 0:
        sekishugo=set(lst)

    else:
       sekishugo = sekishugo.intersection(set(lst))

print((len(sekishugo)))


# Optimized solution
n,m = list(map(int,input().split()))
ans_l = None
ans_r = None
for i in range(m):
    
    l,r = list(map(int,input().split()))

    
    if i == 0:
        ans_l = l
        ans_r = r

    else:
        ans_r = min(r,ans_r)
        ans_l = max(l,ans_l)
        
    if ans_r - ans_l < 0:
        print((0))
        exit()


print((ans_r-ans_l+1))
# Original solution
n, m = list(map(int, input().split()))
can_through = ["1" for _ in range(n)]
# cnt = 0

for i in range(m):
    l, r = list(map(int, input().split()))
    # for j in range(1, n+1):
    #     if can_through[j-1]:
    #         if l <= j <= r:
    #             pass
    #         else:
    #             can_through[j-1] = False

    # print(can_through[:2])
    # print(can_through[2:])
    can_through[:l-1] = "0"*(l-1)
    # print(can_through)
    can_through[r:n] = "0"*(n-r)

    # print(can_through)

print((can_through.count("1")))

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

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

print((max(0, R - L + 1)))
# Original solution
n, m = list(map(int, input().split()))
S = [None]*m

for i in range(m):
    l, r = list(map(int, input().split()))
    S[i] = set(range(l, r+1))

ans = S[0]
for i in range(1, m):
    ans = ans & S[i]

print((len(ans)))


# Optimized solution
n, m = list(map(int, input().split()))
S = [None]*m
L = 0
R = n

for i in range(m):
    l, r = list(map(int, input().split()))
    L = max(l, L)
    R = min(r, R)

ans = R-L+1
if ans < 0:
    ans = 0
print(ans)
# Original solution
N, M = list(map(int, input().split()))

Ls = [0] * M
Rs = [0] * M

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

count = 0
for i in range(N):
    judge = True
    for k in range(M):
        L = Ls[k]
        R = Rs[k]
        if not (L <= i + 1 <= R):
            judge = False
    if judge:
        count += 1
print(count)


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

maxvL = 0
minvR = 1000000
for i in range(M):
    L, R = list(map(int, input().split()))
    if maxvL < L:
        maxvL = L
    if minvR > R:
        minvR = R

count = 0
for i in range(N):
    if maxvL <= i + 1 <= minvR:
        count += 1
print(count)
# Original solution
cardNum,gate = list(map(int,input().split()))
lr = []
for i in range(gate):
  lr.append(list(map(int,input().split())))
okCard = 0
for card in range(1,cardNum+1):
  ok = True
  for check in lr:
    ok = ok and check[0] <= card <= check[1]
    if not ok:
      break
  if ok:
    okCard += 1
print(okCard)

# Optimized solution
cardNum,gate = list(map(int,input().split()))
l = []
r = []
for i in range(gate):
  ll,rr = list(map(int,input().split()))
  l.append(ll)
  r.append(rr)

cnum = min(r)-max(l)+1
if cnum < 0:
  print((0))
else:
  print(cnum)
# Original solution
n,m=list(map(int,input().split()))
g=[]
for i in range(m):
  l,r=list(map(int,input().split()))
  g_list=[]
  for j in range(l,r+1):
    g_list.append(j)
  g.append(g_list)

for k in range(m):

  if k == 0:
    unq=set(g[0])
  else:
    unq=unq&set(g[k])

print((len(list(unq))))


# Optimized solution
n,m=list(map(int,input().split()))
l=[]
r=[]
for i in range(m):
  li,ri=list(map(int,input().split()))
  l.append(li)
  r.append(ri)
 
l_max=max(l)
r_min=min(r)
 
if r_min < l_max:
  print((0))
else:
  print((r_min-l_max+1))
# Original solution
N, M = list(map(int,input().split()))

a = [i for i in range(1,N+1)]
for i in range(M):
    L, R = list(map(int,input().split()))
    aa = [i for i in range(L, R+1)]
    a = set(a) & set(aa)

print((len(a)))

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

pass_num_set = {}

for i in range(M):
    L, R = list(map(int, input().split()))
    if i == 0:
        pass_num_set = set(range(L, R + 1))
    else:
        pass_num_set = pass_num_set & set(range(L, R + 1))

ans = len(pass_num_set)

print(ans)

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

L_list = []
R_list = []

for i in range(M):
    L, R = list(map(int, input().split()))
    L_list.append(L)
    R_list.append(R)
    
ans = max(min(R_list) - max(L_list) + 1, 0)

print(ans)
# Original solution
n, m = list(map(int, input().split()))
gate = []
for i in range(m):
    gate.append(list(map(int, input().split())))

card = [0 for i in range(1, n+1)]

for l, r in gate:
    for i in range(l, r+1):
        card[i-1] += 1
print((card.count(m)))

# Optimized solution
n, m = list(map(int, input().split()))
L_max, R_min = list(map(int, input().split()))
for i in range(m-1):
    L, R = list(map(int, input().split()))
    L_max = max(L_max, L)
    R_min = min(R_min, R)

print((max(R_min - L_max + 1, 0)))
# Original solution
N,M = list(map(int,input().split(" ")))
ans = 0
GATE_ID = []
for i in range(M):
    GATE_ID1,GATE_ID2 = list(map(int,input().split(" ")))
    GATE_ID.append([GATE_ID1,GATE_ID2])
#print(GATE_ID)

for i in range(N):
    CARD_ID = i+1
    #print("CARD_ID:",CARD_ID)
    ALL_GATE_PASS_COUNT = 0
    for j in range(M):
        GATE_ID1,GATE_ID2 = GATE_ID[j][0],GATE_ID[j][1]
        #print(GATE_ID1,GATE_ID2)
        if CARD_ID >= GATE_ID1 and CARD_ID <= GATE_ID2:
            ALL_GATE_PASS_COUNT += 1
            #print(CARD_ID,":PASS")
        else:
            break
    #print("ALL_GATE_PASS_COUNT:",ALL_GATE_PASS_COUNT)
    if ALL_GATE_PASS_COUNT == M:
        ans += 1
print(ans)

# Optimized solution
N,M = list(map(int,input().split(" ")))
L_list = []
R_list = []
for i in range(M):
    L,R = list(map(int,input().split(" ")))
    L_list.append(L)
    R_list.append(R)
if min(R_list) - max(L_list) >= 0:
    print((min(R_list) - max(L_list) +1))
else:
    print((0))
# Original solution
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    
    ans = set(list(range(L[0], R[0]+1)))
    for i in range(1, M):
        ans = ans & set(list(range(L[i],R[i]+1)))

    print((len(ans)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    
    lm = max(L)
    rm = min(R)

    print((max(0, rm-lm+1)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()
# Original solution
N,M = list(map(int,input().split()))
L_list = []
R_list = []
count = 0
M_list = list(range(M))
for i in M_list:
    L,R=list(map(int,input().split()))
    L_list.append(L)
    R_list.append(R)


for i in range(1,N+1):
    for j in M_list:
        if(i >= L_list[j] and i<=R_list[j]):
           
            if j==M-1:
                count+=1
        else:
            break
print(count)

# Optimized solution
N,M = list(map(int,input().split()))
L_list = []
R_list = []
count = 0
min_mn=float('inf')
max_mn=0
for i in range(M):
    L,R=list(map(int,input().split()))
    min_mn = min(min_mn,R)
    max_mn = max(max_mn,L)

for i in range(1,N+1):
    if(i>=max_mn and i<=min_mn):
        count += 1
print(count)
# Original solution
N, M = list(map(int, input().split()))

ans = set()

for i in range(M):
    L, R = list(map(int, input().split()))
    
    if M == 1:
        print((R-L+1))
        break
        
    else:
        if i == 0:
            ans = set(list(range(L, R + 1)))
                
        else:
            s = set(list(range(L, R + 1)))
            ans = ans & s

else:
    print((len(ans)))

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

l = 0
r = N

for i in range(M):
    L, R = list(map(int, input().split()))
    
    if L > l:
        l = L
            
    if R < r:
        r = R
                
    ans = r - l + 1
    if ans < 0:
        print((0))
        break

else:
    print(ans)
# Original solution
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = list(map(int, input().split()))
    counts = [0] * n
    for _ in range(m):
        l, r = list(map(int, input().split()))
        for i in range(l - 1, r):
            counts[i] += 1
    print((counts.count(m)))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


# Optimized solution
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = list(map(int, input().split()))
    l_max = 0
    r_min = float('inf')
    for _ in range(m):
        l, r = list(map(int, input().split()))
        l_max = max(l_max, l)
        r_min = min(r_min, r)
    print((max(r_min + 1 - l_max, 0)))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
# Original solution
N,M = [int(i) for i in input().split()]
ans = [0]*N
for _ in range(M):
    L,R = [int(i)-1 for i in input().split()]
    for j in range(L,R+1):
        ans[j] += 1

count = 0
for i in ans:
    if i == M:
        count += 1

print(count)


# Optimized solution
import sys
input = sys.stdin.readline

N,M = [int(i) for i in input().split()]
L_max = 0
R_min = 10**9
for _ in range(M):
    L,R = [int(i) for i in input().split()]
    L_max = max(L_max,L)
    R_min = min(R_min,R)

if R_min-L_max+1 > 0:
    print((R_min-L_max+1))
else:
    print((0))
# Original solution
import collections

def main():
    li = []
    ans = 0
    n,m = list(map(int,input().split()))
    for _ in range(m):
        l,r = list(map(int, input().split()))
        for i in range(l,r+1):
            li.append(i)
    c = collections.Counter(li)
    for i,v in list(c.items()):
        if v >= m:
            ans += 1
    print(ans)

if __name__ == '__main__':
  main()

# Optimized solution
def main():
    ll = []
    rl = []
    n,m = list(map(int,input().split()))
    for _ in range(m):
        l,r = list(map(int, input().split()))
        ll.append(l)
        rl.append(r)
    l = max(ll)
    r = min(rl)
    print((max(0,r-l+1)))

if __name__ == '__main__':
  main()
# Original solution
N, M = list(map(int, input().split()))
L = [None] * M
R = [None] * M
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))

l = [0] * N
for i in range(M):
    for j in range(L[i], R[i] + 1):
        l[j - 1] += 1
a = 0
for i in range(N):
    if l[i] == M:
        a += 1
print(a)

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

l = [L[0], R[0]] 
for i in range(1, M):
    if L[i] > l[0]:
        l[0] = L[i]
    if R[i] < l[1]:
        l[1] = R[i]

if l[0] <= l[1]:
    ans = l[1] - l[0] + 1
else:
    ans = 0
print(ans)
# Original solution
# indeednow_A_b
import sys
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
L = [0 for i in range(M)]
R = [0 for i in range(M)]
for i in range(M):
    L[i], R[i] = [int(x) for x in stdin.readline().rstrip().split()]
# print(L, R)
ans = set()

for k in range(M):
    temp = set()
    for l in range(L[k], R[k]+1):
        temp.add(l)
    if len(ans) != 0:
        ans = temp & ans
    else:
        ans = temp
print((len(ans)))


# Optimized solution
# indeednow_A_b
import sys
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
L = [0 for i in range(M)]
R = [0 for i in range(M)]
for i in range(M):
    L[i], R[i] = [int(x) for x in stdin.readline().rstrip().split()]
# print(L, R)
ans = set()
ans1 = 0
ans2 = 10**6
for k in range(M):
    if ans2 < L[k]:
        print("0")
        sys.exit()
    if ans1 < L[k]:
        ans1 = L[k]
    if ans2 > R[k]:
        ans2 = R[k]

    # temp = set()
    # for l in range(L[k], R[k]+1):
    #     temp.add(l)
    # if len(ans) != 0:
    #     ans = temp & ans
    # else:
    #     ans = temp
print((ans2+1-ans1))
# Original solution
N, M = list(map(int,input().split()))
LR = [list(map(int,input().split())) for i in range(M)]

ID = [1]*N #IDカードの配列を用意する
for i in range(M):
    for j in range(N):
        if LR[i][0]-1<=j and j<=LR[i][1]-1: #通過できる場合は1をかける
            ID[j] = ID[j]*1
        else: #通過できない場合は0をかける
            ID[j] = ID[j]*0
print((sum(ID))) #全てのゲートをチェックした後、1のままのカードは全てのゲートを通過可能


# Optimized solution
N, M = list(map(int,input().split()))
list_L = []
list_R = []
for i in range(M):
    L, R = list(map(int,input().split()))
    list_L.append(L)
    list_R.append(R)
print((min(list_R)-max(list_L)+1 if min(list_R)>=max(list_L) else 0))
# Original solution
import sys
args = sys.stdin.readlines()
n, m = list(map(int, args[0].split(' ')))
ids = set(range(1, n+1))

for gate in args[1:]:
  l, r = list(map(int, gate.split(' ')))  
  ids = ids & set(range(l, r+1))
  
print((len(ids)))


# Optimized solution
import sys
args = sys.stdin.readlines()
n, m = list(map(int, args[0].split(' ')))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = list(map(int, gate.split(' ')))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print((0))
else:
  print(ids)
# Original solution
# -*- coding: utf-8 -*-

n, m = list(map(int, input().split()))
ok =  [int(i) for i in range(1, n+1)]
answer = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    l = [int(n) for n in range(a, b+1)]
    ok = list(set(ok) & set(l))

print((len(ok)))

# Optimized solution
# -*- coding: utf-8 -*-

n, m = list(map(int, input().split()))
l = []
r = []
answer = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    l.append(a)
    r.append(b)
min_ok = max(l)
max_ok = min(r)
answer = max_ok - min_ok + 1
if answer < 0:
    answer = 0
print(answer)
# Original solution
n, m = [int(x) for x in input().split()]
id_range = []
id_card = [0] * n

for x in range(m):
    id_range.append([int(y) for y in input().split()])

for x in range(m):
    for y in range(id_range[x][0], id_range[x][1] + 1):
        id_card[y - 1] += 1

id_card.sort()
cnt = 0
for x in id_card:
    if(x == m):
        cnt += 1

print(cnt)


# Optimized solution
n, m = [int(x) for x in input().split()]
min_num = 0
max_num = n

for x in range(m):
    tmp_min, tmp_max = list(map(int, input().split()))
    min_num = max(min_num, tmp_min)
    max_num = min(max_num, tmp_max)

if max_num - min_num + 1 > 0:
    print((max_num - min_num + 1))
else:
    print((0))
# Original solution
n,m = list(map(int,input().split()))
answers = [i for i in range(1,n+1)]
for i in range(m):
    l,r = list(map(int,input().split()))
    for ans in answers[:]:
        if ans < l or ans > r:
            answers.remove(ans)
print((len(answers)))


# Optimized solution
n,m = list(map(int,input().split()))
gates = [list(map(int,input().split())) for _ in range(m)]
l = []
r = []
for gate in gates:
    l.append(gate[0])
    r.append(gate[1])
ans = min(r)+1 - max(l)
print((ans if ans > 0 else 0))
# Original solution
N,M = list(map(int,input().split()))
L=[]
R=[]
Nlist = list(range(1,N+1))
for i in range(M):
  L_n,R_n = list(map(int,input().split()))
  L.append(L_n)
  R.append(R_n)
for i in range(M):
  Nlist = [k for k in Nlist if (k > (L[i]-1)) and (k < (R[i]+1))]
print((len(Nlist)))

# Optimized solution
N,M = list(map(int,input().split()))
L=[]
R=[]
Nlist = list(range(1,N+1))
for i in range(M):
  L_n,R_n = list(map(int,input().split()))
  L.append(L_n)
  R.append(R_n)

Lmax=max(L)
Rmin=min(R)
if Rmin < Lmax:
  print((0))
else:
  print((Rmin-Lmax+1))
# Original solution
n,m = list(map(int,input().split()))
src = [tuple(map(int,input().split())) for i in range(m)]

l_max,r_min = 0,10**5
for l,r in src:
    l_max = max(l_max,l)
    
for l,r in src:    
    r_min = min(r_min,r)
else:
    if r_min-l_max < 0:
        print((0))
    else:
        print((r_min-l_max+1))

# Optimized solution
n,m = list(map(int,input().split()))
ll = 0
rr = 10**5+1
for i in range(m):
    l,r = list(map(int,input().split()))
    if l > ll:
        ll = l
    if r < rr:
        rr = r
else:
    #print(rr-ll+1)
    if rr-ll+1>n:
        print(n)
    elif rr-ll+1<0:
        print((0))
    else:
        print((rr-ll+1))
# Original solution
N,M = list(map(int,input().split()))
L_list = []
R_list = []
for o in range(M):
    L,R = list(map(int,input().split()))
    L_list.append(L)
    R_list.append(R)

count = set(range(L_list[0],R_list[0]+1))
for i in range(1,M):
    count = count & set(range(L_list[i],R_list[i]+1))

ans = len(count)
print(ans)

# Optimized solution
N,M = list(map(int,input().split()))
L_list = []
R_list = []
for o in range(M):
    L,R = list(map(int,input().split()))
    L_list.append(L)
    R_list.append(R)
L_max = max(L_list)
R_min = min(R_list)
    
if L_max <= R_min:
    ans = R_min - L_max + 1
else:
    ans = 0
print(ans)
# Original solution
n, m = list(map(int, input().split()))
g = [0] * n
for i in range(m):
    l, r = list(map(int, input().split()))
    for j in range(l-1, r):
        g[j] += 1
ans = 0
for i in range(n):
    if g[i] == m:
        ans += 1
print(ans)


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

for i in range(M):
    if i==0:
        landl=set(range(L[i],R[i]+1))
    else:
        landl=landl & set(range(L[i],R[i]+1))


print((len(landl)))

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

L2=max(L)
R2=min(R)

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

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

for i in range(M):
    L, R = list(map(int, input().split()))
    if L > left:
        left = L
    if R < right:
        right = R

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

for i in range(m):
    l,r = list(map(int, input().split()))
    if l - 1 > left:
        left = l - 1
    if r < right:
        right = r
print((len(ls[left:right])))

# Optimized solution
n, m = list(map(int, input().split()))
left = 0
right = n
ls = list(range(n))

for i in range(m):
    l, r = list(map(int, input().split()))
    if left < l-1:
        left = l-1
    if right > r:
        right = r
print((len(ls[left:right])))
# Original solution
n,m=list(map(int,input().split()))
l,r=list(map(int,input().split()))
s={j for j in range(l,r+1)}
for i in range(1,m):
    l,r=list(map(int,input().split()))
    s=s & {j for j in range(l,r+1)}
    if len(s)==0:
        break
print((len(s)))

# Optimized solution
n,m=list(map(int,input().split()))
l,r=list(map(int,input().split()))
s=[l,r]
for i in range(1,m):
    l,r=list(map(int,input().split()))
    if s[0]<l:
        s[0]=l
    if s[1]>r:
        s[1]=r

    if s[1]-s[0]<0:
        s=[0,-1]
        break
print((s[1]-s[0]+1))