Harryxun/stf_run huggingface dataset:
#ABC157 Guess the number
n,m = map(int,input().split())
sc = [input().split() for _ in range(m)]
ans =[]
if len(sc) == 0:
    print('0')
    exit()

if n == 1:
    d = []
    if m == 1:
        print(sc[0][1])
        exit()
    else:
        for i in range(m):
            d.append(sc[m][1])
        if set(d) == 1:
            print(d[0])
        else:
            print('-1')
            exit()
    
for i in range(10**(n-1),10**n):
    cnt = 0
    seq = str(i)
    for j in range(m):
        if seq[int(sc[j][0])-1] == sc[j][1]:
            cnt += 1
    if cnt == m:
        ans.append(i)
        
if len(ans) == 0:
    print('-1')
else:
    print(min(ans))

### FIXED CODE ###

#ABC157 Guess the number
n,m = map(int,input().split())
sc = [input().split() for _ in range(m)]
ans =[]

if n == 1:
    if len(sc)== 0:
        print('0')
    else:
        ans = []
        for i in range(m):
            ans.append(sc[i][1])
        if len(set(ans)) == 1:
            print(ans[0])
        else:
            print('-1')
    
else:
    for i in range(10**(n-1),10**n):
        cnt = 0
        seq = str(i)
        for j in range(m):
            if seq[int(sc[j][0])-1] == sc[j][1]:
                cnt += 1
        if cnt == m:
            ans.append(i)
        
    if len(ans) == 0:
        print('-1')
    else:
        print(min(ans))
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

d = []
loop = 0

while True:
        for b, c in bc:
                d.extend([c] * b)
                loop += 1
        if len(d) > n:
                break
        elif loop == m:
                break

while True:
        if a[0] < d[0]:
                a.append(d[0])
                del a[0]
                del d[0]
        else:
                break

print(sum(a))

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1    
                        else:
                                break
                        if a_count == n:
                                        break

        else:
                break
        if a_count == n:
                break        

print(sum(a))
a,b,k = map(int, input().split())
sp =[i for i in range(1, max(a,b)) if a%i == 0 and b%i==0]
print(sp[k-1])

### FIXED CODE ###

a,b,k = map(int, input().split())
sp =[i for i in range(1, max(a,b)+1) if a%i == 0 and b%i==0]
sp.sort(reverse=True)
print(sp[k-1])
class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.b, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top

li = map(int, input().split())
D = Dice(li)
command = input()
for dir in command:
    D.rot(dir)
print(D.getTop())


### FIXED CODE ###

class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.n, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top

li = list(map(int, input().split()))
D = Dice(li)
command = input()
for dir in command:
    D.rot(dir)
print(D.getTop())
def main04():
    buf = input("");
    bufs = buf.split(" ");
    val1 = [];
    for i in range(len(bufs)):
        val1.append(int(bufs[i]));
    val2 = [];
    for i in range(val1[0]):
        buf = input("");
        bufs = buf.split(" ");
        kari = [];
        kari.append(int(bufs[0]));
        kari.append(int(bufs[1]));
        val2.append(kari);
    min1 = 10000;
    for i in range(val1[0]):
        if val2[1][i] < val1[1] and val2[0][i] < min1:
            min1 = val2[0][i];
    if min1 == 10000:
        print("TLE");
    else:
        print(min1);

if __name__ == '__main__':
    main04()

### FIXED CODE ###

def main04():
    buf = input("");
    bufs = buf.split(" ");
    val1 = [];
    for i in range(len(bufs)):
        val1.append(int(bufs[i]));
    val2 = [];
    for i in range(val1[0]):
        buf = input("");
        bufs = buf.split(" ");
        kari = [];
        kari.append(int(bufs[0]));
        kari.append(int(bufs[1]));
        val2.append(kari);
    min1 = 10000;
    for i in range(val1[0]):
        if val2[i][1] < val1[1] + 1 and val2[i][0] < min1:
            min1 = val2[i][0];
    if min1 == 10000:
        print("TLE");
    else:
        print(min1);

if __name__ == '__main__':
    main04()
import sys 
sys.setrecursionlimit(1000000) 

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    x, y = map(int, input().split())
    G[x-1].append(y-1)
    G[y-1].append(x-1)


dp = {}
def tdc(p, v):
    if G[v] == [p]:
        dp[(p, v)] = 1
        return 1
    res = 1
    for u in G[v]:
        if u == p: continue
        res *= (1+tdc(v, u)) 
        res %= M
    dp[(p, v)] = res
    return dp[(p, v)]

r = 1       
tdc(-1, r)

ans = [0]*N
ans[r] = dp[(-1, r)]

def buc(p, v):
    if G[v] == [p]: return 0
    nn = len(G[v])
    pf = [1]
    for u in G[v]:
        pf.append(pf[-1]*(dp[(v, u)]+1)%M)
    pb = [1]
    for u in G[v][::-1]:
        pb.append(pb[-1]*(dp[(v, u)]+1)%M)
    for i in range(nn):
        u = G[v][i]
        if u == p: continue
        dp[(u, v)] = pf[i] * pb[::-1][i+1] 
        dp[(u, v)] %= M
        ans[u] = dp[(v, u)]*(1+dp[(u, v)]) 
        ans[u] %= M
        buc(v, u)

buc(-1, r)
print('\n'.join(map(str, ans))) 

### FIXED CODE ###

import sys
 
sys.setrecursionlimit(100000)
 
 
def dfs1(v, p):
    val = 1
    pre_mul = [1]
    rev_mul = []
    for c in links[v]:
        if c == p:
            pre_mul.append(val)
            rev_mul.append(1)
            continue
        res = 1 + dfs1(c, v)
        val *= res
        val %= m
        pre_mul.append(val)
        rev_mul.append(res)
    dp[v] = val
    for i in range(len(rev_mul) - 2, -1, -1):
        rev_mul[i] *= rev_mul[i + 1]
        rev_mul[i] %= m
    rev_mul.append(1)
    pre_muls[v] = [pre_mul, rev_mul]
    return val
 
 
def dfs2(v, p, a):
    dp[v] = dp[v] * a % m
    pmv = pre_muls[v]
    for i, c in enumerate(links[v]):
        if c == p:
            continue
        pmc = pmv[0][i] * pmv[1][i + 1] % m
        pmc = pmc * a % m
        dfs2(c, v, pmc + 1)
 
 
n, m = map(int, input().split())
links = [[] for _ in range(n)]
dp = [0 for _ in range(n)]
pre_muls = [None for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    links[x].append(y)
    links[y].append(x)
dfs1(0, None)
dfs2(0, None, 1)
print('\n'.join(map(str, dp)))
import collections
n = int(input())
v = [int(x) for x in input().split()]
v_odd, v_evn = [], []
for i in range(n):
  if i%2==0:
    v_odd.append(v[i])
  else:
    v_evn.append(v[i])
v_odd_cnt = collections.Counter(v_odd)
v_evn_cnt = collections.Counter(v_evn)
#print(v_odd_cnt, v_even_cnt)
max_kv_odd = max(v_odd_cnt.items(), key=lambda x: x[1])
max_kv_evn = max(v_evn_cnt.items(), key=lambda x: x[1])
if max_kv_odd[0] == max_kv_evn[0]:
  v_odd_cnt_tmp = v_odd_cnt
  v_evn_cnt_tmp = v_evn_cnt
  v_odd_cnt_tmp.pop(max_kv_odd[0])
  v_evn_cnt_tmp.pop(max_kv_evn[0])
  max_kv_odd_tmp = max(v_odd_cnt_tmp.items(), key=lambda x: x[1])
  max_kv_evn_tmp = max(v_evn_cnt_tmp.items(), key=lambda x: x[1])
  a = max_kv_odd[1] + max_kv_evn_tmp[1]
  b = max_kv_evn[1] + max_kv_odd_tmp[1]
  print(n-max(a, b))
  exit()
print(n-max_kv_odd[1]-max_kv_evn[1])
'''
v_odd = [0] * 10**5
veven = [0] * 10**5
for i in range(0, n//2+1, 2):
  v_odd[v[i]] += 1
  veven[v[i+1]] += 1
for i, x in enumerate(v_odd):

v_odd = {}
veven = {}
for i in range(0, n//2+1, 2):
  v_odd[v[i]] = v_odd.get(v[i], 0) + 1
  veven[v[i+1]] = veven.get(v[i+1], 0) + 1
'''

### FIXED CODE ###

import collections
n = int(input())
v = [int(x) for x in input().split()]
v_odd, v_evn = [], []
for i in range(n):
  if i%2==0:
    v_odd.append(v[i])
  else:
    v_evn.append(v[i])
v_odd_cnt = collections.Counter(v_odd)
v_evn_cnt = collections.Counter(v_evn)
if len(v_odd_cnt) == len(v_evn_cnt) == 1:
  if v[0] == v[1]:
    print(n//2)
    exit()
  else:
    print(0)
    exit()
max_kv_odd = max(v_odd_cnt.items(), key=lambda x: x[1])
max_kv_evn = max(v_evn_cnt.items(), key=lambda x: x[1])
if max_kv_odd[0] == max_kv_evn[0]:
  if len(v_odd_cnt) == 1:
    v_evn_cnt.pop(max_kv_evn[0])
    max_kv_evn_tmp = max(v_evn_cnt.items(), key=lambda x: x[1])
    print(n-max_kv_odd[1]-max_kv_evn_tmp[1])
    exit()
  if len(v_evn_cnt) == 1:
    v_odd_cnt.pop(max_kv_odd[0])
    max_kv_odd_tmp = max(v_odd_cnt.items(), key=lambda x: x[1])
    print(n-max_kv_odd_tmp[1]-max_kv_evn[1])
    exit()
  v_odd_cnt_tmp = v_odd_cnt
  v_evn_cnt_tmp = v_evn_cnt
  v_odd_cnt_tmp.pop(max_kv_odd[0])
  v_evn_cnt_tmp.pop(max_kv_evn[0])
  max_kv_odd_tmp = max(v_odd_cnt_tmp.items(), key=lambda x: x[1])
  max_kv_evn_tmp = max(v_evn_cnt_tmp.items(), key=lambda x: x[1])
  a = max_kv_odd[1] + max_kv_evn_tmp[1]
  b = max_kv_evn[1] + max_kv_odd_tmp[1]
  print(n-max(a, b))
  exit()
print(n-max_kv_odd[1]-max_kv_evn[1])
N,M,X= map(int,input().split())
A=[list(map(int,input().split()) for i in range(N)]
K=np.array([0*M])
m=[]

import numpy as np


def dfs(i, sum,K):
    # n 個決め終わったら、今までの和 sum が k と等しいかを返す
    if i == N:
        for j in K:
            count=0
            while j>=X:
                count+=1
        if count==M
            m.append(sum)
        return count==M
            

    # a[i] を使わない場合
    if dfs(i + 1, sum+K[i][0],K+np.array([for j in A[i][1:]]):
        return True

    # a[i] を使う場合
    if dfs(i + 1, sum,K):
        return True

    # a[i] を使う使わないに拘らず k が作れないので False を返す
    return False
print(min(m) if dfs(0,0,K) else -1)



### FIXED CODE ###

n,m,x=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
ans=[]
for bit in range(1<<n):
  total=0
  skill=[0]*m
  for i in range(n):
    if bit & (1<<i):
      total+=a[i][0]
      for j in range(m):
        skill[j]+=a[i][j+1]
  if all([k>=x for k in skill]):
    ans.append(total)
print(min(ans) if len(ans)!=0 else -1)
x = int(input())
a = [list(map(int,input().split()))]
b = sorted(a)
y = 0
for i in range(x):
  y += b[i-0]*(2**i)
print(y//(2**(x+1)))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort()
sum = a[0]
for i in range(1,n):
    sum = (sum + a[i])/2
print(sum)
list=[]

def partition(p,r):
	t=0
	x=list[r]
	i=p-1
	j=p
	while(j<r):
		if(int(list[j])<=x):
			i+=1
			t=int(list[i])
			list[i]=list[j]
			list[j]=t
		j+=1

	t=int(list[i+1])
	list[i+1]=list[r]
	list[r]=t

	return i+1

def main():
	n=int(input())
	i=0
	while(i<n):
		list.append(int(input()))
		i+=1

	q=partition(0,n-1)
	i=0
	while(i<n):
		if(i==q):
			print("[",end="")
			print(str(list[i]),end="")
			print("] ",end="")
		else:
			print(str(list[i])+" ",end="")
		i+=1
	print()
	return 0

if __name__ == "__main__":
	main()



### FIXED CODE ###

def partition(a, left, right):
    pivot = a[right-1]
    i = left - 1
    for j in range(left, right-1):
        if a[j] <= pivot:
            i += 1
            a[i], a[j] = a[j], a[i]
    a[i+1], a[right-1] = a[right-1], a[i+1]
    return i + 1
 
def main():
    n = int(input())
    a = list(map(int, input().split()))
    p = partition(a, 0, len(a))
    a[p] = '[' + str(a[p]) + ']'
    print(' '.join(map(str, a)))
 
if __name__ == '__main__':
    main()
import sys

def main(args):
    # given = [(i, int(args[i])) for i in range(len(args))]
    # ans = sorted(given, key=lambda elm: elm[1])
    # print(ans[0][1]+1)

    ans = [1,2,3,4,5]
    given = [int(i) for i in args]

    for i in range(len(ans)):
        if ans[i] != given[i]:
            print(ans[i])
            break

main(sys.argv[1:])

### FIXED CODE ###

#!python
given = [int(i) for i in input().split()]
ans = [1,2,3,4,5]

for i in range(len(ans)):
    if ans[i] != given[i]:
        print(ans[i])
        break
s=input()
p=list(set(list(s)))
a=[]
for i in p
    a.append(s.count(i))
for x in a:
    if x%2!==0:
        print("No")
        exit()
print("Yes")


### FIXED CODE ###

s=input()
p=list(set(list(s)))
a=[]
for i in p:
    a.append(s.count(i))
for x in a:
    if x%2!=0:
        print("No")
        exit()
print("Yes")
S=input()

T=["AKIHABARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA"]
T+=["AKIHABR","AKIHBAR","KIHABAR","AKIHBRA","KIHABRA","KIHBARA"]
T+=["KIHABR","KIHBAR","KIHBRA","AKIHBR","KIHBR"]
#print(T)

prin("YES" if S in T else "NO")

### FIXED CODE ###

S=input()

T=["AKIHABARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA"]
T+=["AKIHABR","AKIHBAR","KIHABAR","AKIHBRA","KIHABRA","KIHBARA"]
T+=["KIHABR","KIHBAR","KIHBRA","AKIHBR","KIHBR"]
#print(T)

print("YES" if S in T else "NO")
def main():
    N = int(input())

    i = 1
    sum = 0
    temp = 0
    while True:
        temp = 0
        i += 1
        sum += 1
        for j in range(1,i):
            temp += 26**j

        if N <= temp:
            break

    # 文字数はsum
    #for j in range(1,sum):
        #temp += 26**j
    #N -= temp

    ans = []
    flag = 0
    cnt = 0
    for j in range(sum):
        amari = N%26
        if amari == 0:
            flag = 1
            cnt += 1
            if cnt == 1:
                #print(amari,flag)
                ans.append(amari)
                N = N//26
                continue
        N = N//26
        #print(amari,flag)
        ans.append(amari-flag)

    #print(ans)

    ans2 = [0]*(sum)
    dict = {1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',11:'k',12:'l',13:'m',14:'n',15:'o',16:'p',17:'q',18:'r',19:'s',20:'t',21:'u',22:'v',23:'w',24:'x',25:'y',0:'z'}
    for j in range(sum):
        ans2[sum-1-j] = dict[ans[j]]
    print(''.join(ans2))


main()


### FIXED CODE ###

def main():
    N = int(input())

    i = 1
    sum = 0
    temp = 0
    while True:
        temp = 0
        i += 1
        sum += 1
        for j in range(1,i):
            temp += 26**j

        if N <= temp:
            break

    #文字数はsum
    temp = 0
    for j in range(1,sum):
        temp += 26**j
    #print(N)
    N -= (temp+1)
    #print(N,sum)

    ans = []
    for j in range(sum):
        amari = N%26
        N = N//26
        #print(amari,flag)
        ans.append(amari)

    ans2 = [0]*len(ans)
    dict = {0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j',10:'k',11:'l',12:'m',13:'n',14:'o',15:'p',16:'q',17:'r',18:'s',19:'t',20:'u',21:'v',22:'w',23:'x',24:'y',25:'z'}
    for j in range(sum):
        ans2[sum-1-j] = dict[ans[j]]
    print(''.join(ans2))


main()
W=["dream", "dreamer", "erase", "eraser" ]
def srch(word):
    if word=="":
        print("YES")
        exit()

    for w in W:
        if word[:len(w)] == w:
            srch(word[len(w):])

srch(input())
print("NO")


### FIXED CODE ###

W=["dream", "dreamer", "erase", "eraser"]
word=input()
while True:
    if word=="":
        print("YES")
        exit()

    ok = False
    for w in W:
        if word[-len(w):] == w:
            word = word[:-len(w)]
            ok = True
            break

    if not ok:
        print("NO")
        exit()
import math
a, b = map(int, input().split())
print(math.lcm(a, b))


### FIXED CODE ###

import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b = map(int, input().split())
print(lcm(a, b))
import sys

np = input().split()
n = int(np[0])
p = int(np[1])
bound_p = int(p ** (1 / n))


ilist = list(range(1, bound_p + 1))
ilist.reverse()


for i in ilist:
    if p % (i**n) == 0:
        print(i)
        sys.exit(0)

print(1)


### FIXED CODE ###

import sys

np = input().split()
n = int(np[0])
p = int(np[1])
bound_p = int(p ** (1 / min(n, 4)))


if n == 1:
    print(p)
    sys.exit(0)


ilist = list(range(2, bound_p + 1))
ilist.reverse()


for i in ilist:
    pp = p
    for j in range(n):
        if pp % i != 0:
            break
        pp = pp // i
    else:
        print(i)
        sys.exit(0)


print(1)
S=input()
if len(S)<26:
    raise TypeError
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            print(S[:26-len(tmp)]+sorted(tmp)[1])
            exit()
    print(-1)

### FIXED CODE ###

S=input()
if len(S)<26:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            tmp =sorted(tmp)
            print(S[:26-len(tmp)]+tmp[tmp.index(S[24-i])+1])
            exit()
    print(-1)
import math

k = int(imput())
n = 0

for i in range(1,k+1)
    for j in range(1,k+1)
        a=math.gcd(i,j)
        for l in range(1,k+1)
            b=math.gcd(a,l)
            n += b

print(n)

### FIXED CODE ###

import math

k = int(input())
n = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            b = math.gcd(a,l)
            n += b

print(n)
from fractions import gcd

#####segfunc######                                                              
def segfunc(x,y):
    return gcd(x,y)

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
	seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
	k=(k-1)//2
	seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
	return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
	if p&1==0:
            res=segfunc(res,seg[p])
	if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
	p=p//2
	q=(q-1)//2
    if p==q:
	res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n=int(input())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
a=list(map(int,input().split()))

ans=0
for i in range(n):
    ans=min(gcd(query(0,i),query(i+1,n)),ans)
print(ans)


### FIXED CODE ###

from fractions import gcd

#####segfunc######                                                              
def segfunc(x,y):
    return gcd(x,y)

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n=int(input())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
a=list(map(int,input().split()))
init(a)
ans=0
for i in range(n):
    ans=max(gcd(query(0,i),query(i+1,n)),ans)
print(ans)
A,B=int(input())

if A<6:
  print(0)
if 6<=A<12:
  print(B/2)
else:
  print(B)



### FIXED CODE ###

A,B=map(int,input().split())

if A<6:
  print(0)
elif 6<=A<=12:
  print(B//2)
else:
  print(B)
def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
            v = A[i]
            j = i - g
            while j >= 0 and A[j] > v:
                    A[j+g] = A[j]
                    j = j - g
                    cnt += 1
                    A[j+g] = v
    return cnt
def shellsort(A,n):
    cnt = 0
    h = 1
    G = []
	while h <= 1:
        G.append(h)
        h = 3*h + 1
    G.reverse()

    print(len(G))

    print(" ".join(map(str,G)))
    for i in range(len(G)):
        cnt += insertionSort(A,n,G[i])
    print(cnt)
    for i in A:
        print(i)
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
shellsort(A,n)




### FIXED CODE ###

def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
            A[j+g] = v
    return cnt
    
def shellsort(A,n):
    cnt = 0
    h = 1
    G = []
    while h <= n:
        G.append(h)
        h = 3*h + 1
    G.reverse()
    m = len(G)
    print(m)

    print(" ".join(map(str,G)))
    for i in range(m):
        cnt += insertionSort(A,n,G[i])
    print(cnt)
    for i in A:
        print(i)
        
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
shellsort(A,n)
10 3
3 6
5 7
6 9

### FIXED CODE ###

N, M = map(int, input().split())
maxL = 0
minM = N
for x in range(M):
    l, m = map(int, input().split())
    maxL = max(maxL, l)
    minM = min(minM, m)

print(max(minM - maxL + 1, 0))