Harryxun/stf_run huggingface dataset:
from functools import lru_cache
import sys
N, X = map(int, input().split())
sys.setrecursionlimit(1_000_000_000)


@lru_cache(maxsize=1000)
def dfs(level, idx, cnt_p):
    if X == idx+1:
        return 0
    elif X < 2**(level+1)-3+2:
        return cnt_p + dfs(level-1, idx+1, cnt_p)
    elif X == 2**(level+1)-3+2:
        return 2**(level)-1 + 1
    else:
        return cnt_p + 2**(level)-1 + 1 + dfs(level-1, idx+2**(level+1)-2, cnt_p)


ans = dfs(N, 0, 0)
print(ans)


### FIXED CODE ###

N,X = map(int, input().split())

a,p = [1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(n,x):
    if n==0:
        return 1 if x>=1 else 0
    if x==1:
        return 0
    elif x<=1+a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1]+1+f(n-1, x-2-a[n-1])
    
print(f(N,X))
aaa = [int(input(i)) for i in range(6)]

ans = "Yay!"

a = aaa[0]
for i in range(1,5):
	if aaa[5] >= a - aaa[i]:
    	ans = ":("
      	break
   
 print(ans)

### FIXED CODE ###

aaa = [int(input()) for i in range(6)]
 
ans = "Yay!"

j = aaa[4] - aaa[0]

if j > aaa[5]:
  ans = ":(" 

print(ans)
k,s = input().split()
for l in range(k):
    for m in range(k):
        if(s-l-m <= k):
            print(l,m,s-l-m)


### FIXED CODE ###

inputs= list(map(int,input().split()))
k = inputs[0]
s = inputs[1]
answer = 0
for i in range(k+1):
  x = i
  for l in range(k+1):
    y = l
    z = s-x-y
    if z >= 0 and z <= k :
      answer += 1
print(answer)
import numpy as np

def is_ok(m):
    tmp = h - B*m

    if not any(tmp):
        return False
    
    rem = sum([np.ceil(i/(A-B)) for i in tmp])

    if rem > m:
        return False

    return True

N,A,B = map(int,input().split())
h = np.array(list(int(input()) for _ in range(N)))
s = np.sum(h)
##二分散策

r = 10**10
l = 0

while abs(l-r) > 1:

    m = (r+l)//2

    if is_ok(m):
        r = m
    else:
        l = m

print(r)

### FIXED CODE ###

import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def check(k):
    tmp = list(h)
    for i in range(N):
        tmp[i] -= B*k
    if sum([int(i<=0) for i in tmp]) == N:
        return True

    lf = 0
    for i in tmp:
        if i > 0:
            lf += ceil(i/(A-B))

    if lf <= k:
        return True
    else:
        return False

N,A,B = map(int,input().split())
h = tuple(int(input()) for _ in range(N))

left = -1
right = 1e9

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))
N,A,B = (int(x) for x in input().split())
S =  n % (A+B) - A
Acount = n % (A+B)
Ansn = n / (A+ B) * A
if S <= 0
    print(Ansn + Acount)
else
    print(Ansn + A)

### FIXED CODE ###

N,A,B = (int(x) for x in input().split())
S =  N % (A+B) - A
Acount = N % (A+B)
Ansn = int(N / (A + B)) * A
if S <= 0:
    print(Ansn + Acount)
else:
    print(Ansn + A)
a = input().split()
n = a[0]
l = a[1]

sum_ = 0
for i in range(n-1):
    sum_ = sum_ + (l + i - 1)

taste = [] 

for i in range(n):
    taste = sum_ - (l + i - 1)

min_sa = 0
sa = 0

for i in range(n):
    sa = sum_ - teste[i]
    if sa < min_sa:
        min_sa = sa

for i in range(n):
    if (sum_ - taste[i]) == min_sa:
        print(taste[i])
        return

### FIXED CODE ###

num = input()
#num = str(code)

if num[0] == num[1] or num[1] == num[2] or num[2] == num[3]:
    print('Bad')
else:
    print('Good')
k, yen = [int(x) for x in input("Enter two value: ").split()]
print('Yes') if k*500>=yen else print('No)

### FIXED CODE ###

[k, yen] = [int(x) for x in input().split()]
print('Yes') if k*500>=yen else print('No')
Q, H, S, D = map(int, input().split())
N = int(input())
arr = [4*Q*N, 2*H*N, S*N]
if N % 2 == 0:
  arr.append(int(0.5*D*N))
elif:
  if N >= 3:
    arr.append(int(0.5*D*(N-1)+ min(S, 2*H, 4*Q)))
    
print(min(arr))

### FIXED CODE ###

Q, H, S, D = map(int, input().split())
N = int(input())
x = N % 2
y = N // 2
arr = [4*Q*x, 2*H*x, S*x]
arr1 = [8*Q*y, 4*H*y, 2*S*y, D*y]
#if N % 2 == 0:
#  arr.append(int(0.5*D*N))
#else:
#  arr.append(int(0.5*D*(N-1)+ min(S, 2*H, 4*Q)))
   
print(min(arr) + min(arr1))
s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    return a == b
  
cand = []
for i in range(len(s)-len(t)+1):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    cs = ''.join(c)
    cand(cs.replace('?', 'a'))
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")
    


### FIXED CODE ###

s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    return a == b
  
cand = []
for i in range(len(s)-len(t)+1):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    cs = ''.join(c)
    cand.append(cs.replace('?', 'a'))
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")
s = input()
K = int(input())
subs = []
alphabet = list("abcdefghijklmnopqrstuvwxyz")
result = []

for u in alphabet:
    for i in range(len(s)):
        if s[i] == u:
            for j in range(i + 1, min(i + K + 1, len(s) + 1)):
                result.append(s[i:j])


subs = list(set(subs))
subs.sort()
print(subs[K - 1])


### FIXED CODE ###

s = input()
K = int(input())
subs = []
for i in range(0, len(s)):
    for j in range(i + 1, K + i + 1 if i + K <= len(s) else len(s) + 1):
        subs.append(s[i:j])


subs = list(set(subs))

subs.sort()
print(subs[K - 1])
def solve():
    N, P = map(int, input().split())
    
    ans = 1
    if n==1:
        return P
    else:
        for i in range(2, int(P**(1/N)+1)):
            while P % (i**N) == 0:
                ans *= i
                P //= (i**N)
        return ans
print(solve())

### FIXED CODE ###

def solve():
    N, P = map(int, input().split())
    
    ans = 1
    if N==1:
        return P
    else:
        for i in range(2, int(P**(1/N)+1)):
            while P % (i**N) == 0:
                ans *= i
                P //= (i**N)
        return ans
print(solve())
c=input()
alp="abcdefghijklmnopqrstuvwxyz"
for i in range(25):
  if c==alp[i]:
    print(alh[i+1])
    break
              

### FIXED CODE ###

c=input()
alp="abcdefghijklmnopqrstuvwxyz"
for i in range(25):
  if c==alp[i]:
    print(alp[i+1])
    break
import numpy as np
a = np.arange(L, L + N)
d = abs(a).argmin() # argmin: ndarrayで最小値の要素のインデックスを取得
print(a.sum() - a[d])

### FIXED CODE ###


n,l=map(int,input().split())
aji_lis=[int(l+i-1) for i in range(1,n+1)]

N_sum=sum(aji_lis)
ap=min([abs(i) for i in aji_lis])

if N_sum >=0:
    print(N_sum-ap)
else:
    print(N_sum+ap)
from collections import defaultdict
import math
import numpy as np
N, X, Y = map(int, input().split(' '))
d = defaultdict(int)
for i in range(1, N):
    for k in range(i+1, N+1):
        if(k < X):
            ans = k-i
            d[ans] += 1
        else:
            ans = min(k-i, abs(Y-k)+1+abs(i-X))
            d[ans] += 1

for i in range(1, N):
    print(d[i])


### FIXED CODE ###

from collections import defaultdict
import math
import numpy as np
N, X, Y = map(int, input().split(' '))
d = defaultdict(int)
for i in range(1, N):
    for k in range(i+1, N+1):
        if(k < X):
            ans = k-i
            d[ans] += 1
        else:
            ans = min(k-i, abs(Y-k)+1+abs(i-X))
            d[ans] += 1

for i in range(1, N):
    print(d[i])
import numpy as np
A= np.array([list(map(int,input()split())) for I in range (3)])

for I in range (2):
    j,k,l = A[1]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
    j,k,l = A[2]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
print("Yes")

### FIXED CODE ###

import numpy as np
A= np.array([list(map(int,input().split())) for I in range (3)])

for I in range (2):
    j,k,l = A[1]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
    j,k,l = A[2]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
print("Yes")
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

a=int(input())
b=int(input())
c=int(input())

if 7 == a:
    if 5 == b and 5 == c:
        print("YES")
elif 5 == a:
    if (7 == b and 5 == c) or (5 == b and 7 == c):
        print("YES")
else:
    print("NO")

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

a = list(map(int, input().split()))

if 7 == a[0]:
    if 5 == a[1] and 5 == a[2]:
        print("YES", end="\n")
    else:
        print("NO", end="\n")   

elif 5 == a[0]:
    if (7 == a[1] and 5 == a[2]) or (5 == a[1] and 7 == a[2]):
        print("YES", end="\n")
    else:
        print("NO", end="\n")   
else:
    print("NO", end="\n")
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

# a, bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

# a, bの最小公倍数
def lcm(a, b):
    return a * b / gcd(a,b)

# リストnumbers最小公倍数
def lcmlist(numbers):
    a = numbers[0]
    for i in range(1, len(numbers)):
        a = lcm(a, numbers[i])
    return a

#### START
n = int(input())
t = [int(input()) for i in range(n)]

print(lcmlist(t))


### FIXED CODE ###

# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

# a, bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

# a, bの最小公倍数
def lcm(a, b):
    return int(a * b) // gcd(a,b)

# リストnumbers最小公倍数
def lcmlist(numbers):
    a = numbers[0]
    for i in range(1, len(numbers)):
        a = lcm(a, numbers[i])
    return int(a)

#### START
n = int(input())
t = [int(input()) for i in range(n)]

print(lcmlist(t))
from collections import deque
n,k=map(int,input().split())
v=[int(_) for _ in input().split()]
num=min(n,k)
fans=0
for lll in range(num):
  for rrr in range(num-lll):
    rest=k-lll-rrr
    if rrr!=0:
      pick=v[:lll]+v[-rrr:]
    else:
      pick=v[:lll]
  ans=sum(pick)
  pick=sorted(pick)
  for iii in range(rest):
    if pick[iii]<0:
      ans-=pick[iii]
  fans=max(ans,fans)
print(fans)

### FIXED CODE ###

from collections import deque
n,k=map(int,input().split())
v=[int(_) for _ in input().split()]
num=min(n,k)
fans=0
for lll in range(num+1):
  for rrr in range(num-lll+1):
    rest=k-lll-rrr
    if rrr!=0:
      pick=v[:lll]+v[-rrr:]
    else:
      pick=v[:lll]
    ans=sum(pick)
    pick=sorted(pick)
    for iii in range(min(rest,len(pick))):
      if pick[iii]<0:
        ans-=pick[iii]
    fans=max(ans,fans)
print(fans)
n = int(input())
S = input()
c = S[::-1]
w,b = 0,0

for i in range(len(S)):
    if S[i] != '.':
        break

for e in range(len(c)):
    if c[e] != '#':
        break

for s in range(d,len(S)-e+1):
    if S[s] == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    print(b)


### FIXED CODE ###

n = int(input())
S = [s for s in input()]
w,b = [0],[0]
for i in range(n):
    if S[i] is '#': w.append(w[i]+1)
    else:   w.append(w[i])
    if S[n-i-1] is '.': b.append(b[i]+1)
    else:   b.append(b[i])
b = b[::-1]
#print(w,b)
ans = float('inf')
for i in range(n+1):
    ans = min(ans, w[i]+b[i])
print(ans)
N = int(input())
S = input()
Sr = []

al = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for i in range(len(S)):
  m = al.index(S[i])
  n = (1 + n + N) % 26 - 1
  Sr.append(al[n])
  
print(''.join(Sr))

### FIXED CODE ###

N = int(input())
S = input()
Sr = []

al = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for i in range(len(S)):
  n = al.index(S[i])
  Sr.append(al[(1 + n + N) % 26 - 1])
  
print(''.join(Sr))
s = input()

if len(list(set(s))) >= 3:
  print("No")
else:
  s = list(set(s))
  if s.count(s[0]) == s.count(s[1]):
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

s = input()
s_s = list(set(s))

if len(s_s) == 2:
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
else:
    print('No')
def divide(x, y):
    s = 1
    if(x < 0):s *= -1
    if(y < 0):s *= -1
    if x == 0:exit(0)
    return abs(x) / abs(y) * s     
 
def _split(_src):
    c = 0
    l = len(_src)
    if l == 0:
        return []
    while c < l and ord('0') <= ord(_src[c]) <= ord('9'):
        c += 1
    if c == 0:
        tmp = _split(_src[1:])
        if tmp != [] and tmp[0] == "-":
            tmp = ["(", 0 , "-", 1, ")", "*"] + tmp[1:]
        return [_src[0]] + tmp
    else:
        return [int(_src[:c])] + _split(_src[c:])
         
 
def evaluate(src):
    if len(src) == 1:
        return src[0]
         
    if "(" in src:
        l = src.index("(")
        r = src.index(")")
        mid = evaluate(src[l + 1:r])
        return evaluate( src[:l] + [mid] + src[r + 1:])
     
    operators = [("+", lambda x,y:x + y),
                 ("-", lambda x,y:x - y),
                 ("*", lambda x,y:x * y),
                 ("/", divide)
                ]  
     
    for (op,func) in operators:
        if op in src:
            p = src.index(op)
            l = evaluate(src[:p])
            r = evaluate(src[p + 1:])
            return func(l, r)
     
     
for t in xrange(input()):
    _src = "0+" + raw_input()[:-1]
    src = _split(_src)
    print evaluate(src)

### FIXED CODE ###

def divide(x, y):
    s = 1
    if(x < 0):s *= -1
    if(y < 0):s *= -1
    return abs(x) / abs(y) * s     

operator = {"+":(lambda x,y: x+y),
            "-":(lambda x,y: x-y),
            "*":(lambda x,y: x*y),
            "/":divide
            }

def ind(src, x):
    if x not in src:return 1<<30
    return src.index(x)
 
def _split(_src):
    c = 0
    l = len(_src)
    if l == 0:
        return []
    while c < l and ord('0') <= ord(_src[c]) <= ord('9'):
        c += 1

    if c == 0:
        return [_src[0]] + _split(_src[1:])
    else:
        return [int(_src[:c])] + _split(_src[c:])
         
 
def evaluate(src):
    if len(src) == 1:
        return src[0]
         
    if "(" in src:
        l = src.index("(")
        r = l
        st = 1
        while st:
            r += 1
            if src[r] == "(": st += 1
            if src[r] == ")": st -= 1
        
        mid = evaluate(src[l + 1:r])
        return evaluate( src[:l] + [mid] + src[r + 1:])
    
    pos = min(ind(src, "*"), ind(src,"/"))
    if(pos == 1<<30):
        pos = min(ind(src, "+"), ind(src, "-"))
    op = src[pos]
    l, r = src[pos - 1], src[pos + 1]
    mid = operator[op](l, r)
    return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])

     
for t in xrange(input()):
    _src = raw_input().strip("=")
    src = _split(_src)
    print evaluate(src)
import sys
import time

class Node:
    def __init__(self, key = None):
        self.key = key
        self.left = None
        self.right = None

def insert(key):
    global root
    z = Node(key)
    y = None
    x = root
    while x:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right

    if y is None:
        root.key = key
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def inorderTreeWalk(node):
    if node:
        return inorderTreeWalk(node.left) + " " + str(node.key) + inorderTreeWalk(node.right)
    return ""

def preorderTreeWalk(node):
    if node:
        return " " + str(node.key) + preorderTreeWalk(node.left) + preorderTreeWalk(node.right)
    return ""

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "i":
            insert(int(line.split()[1]))
        else:
            print inorderTreeWalk(root)
            print preorderTreeWalk(root)

### FIXED CODE ###

import sys

class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def inorderTreeWalk(node):
    global In
    if node:
        inorderTreeWalk(node.left)
        In.append(str(node.key))
        inorderTreeWalk(node.right)

def preorderTreeWalk(node):
    global Pre
    if node:
        Pre.append(str(node.key))
        preorderTreeWalk(node.left)
        preorderTreeWalk(node.right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "i":
            insert(Node(int(line.split()[1])))
        else:
            In = []
            Pre = []
            inorderTreeWalk(root)
            print " " + " ".join(map(str, In))
            preorderTreeWalk(root)
            print " " + " ".join(map(str, Pre))
N, M, K = map(int, input().split())
uf = UnionFind(N)
a = [0] * M
b = [0] * M
for i in range(M):
    a[i], b[i] = map(int, input().split())
    uf.union(a[i]-1, b[i]-1)

ans = [uf.size(i) - 1 for i in range(N)]

for i in range(M):
    if uf.same(a[i]-1, b[i]-1):
        ans[a[i]-1] -= 1
        ans[b[i]-1] -= 1

for i in range(K):
    c, d = map(int, input().split())
    if uf.same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

print(' '.join(map(str, ans)))

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, input().split())
uf = UnionFind(N)
a = [0] * M
b = [0] * M
for i in range(M):
    a[i], b[i] = map(int, input().split())
    uf.union(a[i]-1, b[i]-1)

ans = [uf.size(i) - 1 for i in range(N)]

for i in range(M):
    if uf.same(a[i]-1, b[i]-1):
        ans[a[i]-1] -= 1
        ans[b[i]-1] -= 1

for i in range(K):
    c, d = map(int, input().split())
    if uf.same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

print(' '.join(map(str, ans)))
import math
n=int(input())
l=list(map(int,input().split())).sort()
for i,x in enumerate(l):
  if n%2 and x!=int((i+1)/2):
    print(0)
  else:
    if i%2 and i+1!=x:
      print(0)
    elif i!=x:
      print(0)
      
else:
  print(((n/2)**2)%10**9+7)

### FIXED CODE ###

N=int(input())
l=list(map(int,input().split()))
a=1
if N%2==0:
    if len(l)!=len(set(l))*2:
        a=0
else:
    if l.count(0) == 1:
        l.remove(0)
        if len(l) != 2*len(set(l)):
            a = 0
    else:
        a=0
if a:
      print((2**(N//2))%(10**9+7))
else:
      print(0)
n,m = [int(i) for i in input().split()]
l = sorted([[int(i) for i in input().split()] for _ in range(n)],key = lambda x: (x[1]))
l2 = sorted(l,key = lambda x :x[0])

min_atk = l2[n-1][0]
ct = 0
for i in range(len(l)-1,0,-1):
    if l[i][1] >= min_atk and m >= 0:
        m -= l[i][1]
        ct += 1
    else:
        break

if m < 0:
    print(ct)
else:
    q,r = divmod(m,min_atk)
    ct += (m//min_atk) +( 1 if r > 0 else 0 )
    
print(ct)


### FIXED CODE ###

x,y = [int(i) for i in input().split()]
ans =[]

for i in range(x+1):
    if not ans:
        for j in range(x-i+1):
            if 10000*i + j*5000 + (x-i-j)*1000 == y:
                ans = [i,j,x-i-j]
                break
    else:
        break

if ans:
    print(ans[0],ans[1],ans[2])
else:
    print('-1 -1 -1')
a,b = map(int,input().split())
print(max(0,int(a-2b)))

### FIXED CODE ###

a,b = map(int,input().split())
print(max(0,int(a-2*b)))
import math
N,M = map(int, input().split())
def combinations_count(n,r):
	return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))
print(combinations_count(N,2) + combinations_count(M,2))

### FIXED CODE ###

import math
N,M = map(int, input().split())
def combinations_count(n,r):
	if n == 0 or n == 1:
		return 0
	elif n == 2:
		return 1
	else: return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))
print(combinations_count(N,2) + combinations_count(M,2))
def test(a, b):
  if a*b % 2 == 0:
    print("Even")
  else:
    print("Odd")
test(a, b)

### FIXED CODE ###

def main():
  a, b = map(int, input().split())
  if a*b % 2 == 0:
    print("Even")
  else:
    print("Odd")
main()
n,m = map(int,input().split())
s = [0]*m
c = [0]*m
for i in range(m):
  s[i],c[i] = map(int,input().split())
ans = [0]*n

flag = 0

if n == 1:
  for i in range(m-1):
    if c[0]!=c[i+1]:
      flag=-1
      break
  if flag == 0:
    print(c[0])
  else: print(-1)
      
if n == 2:
  for i in range(m):
    ans[s[i]-1]=c[i]
  for i in range(m):
    if ans[s[i]-1]!=c[i]:
      flag=-1
      break
  if ans[0] == 0:
    print(-1)
  elif flag == 0:
    print(ans[0]*10+ans[1])
  else: print(-1)

if n == 3:
  for i in range(m):
    ans[s[i]-1]=c[i]
  for i in range(m):
    if ans[s[i]-1]!=c[i]:
      flag=-1
      break
  if ans[0]==0:
    print(-1)
  elif flag == 0:
    print(ans[0]*100+ans[1]*10+ans[2])
  else: print(-1)

### FIXED CODE ###

n,m = map(int,input().split())

ans = [0]*n
ans[0] = 1

misnot = 0

if m == 0:
  misnot=1

s = [0]*m
c = [0]*m
for i in range(m):
  s[i],c[i] = map(int,input().split())

flag = 0
if misnot == 0:
  if n == 1:
    for i in range(m-1):
      if c[0]!=c[i+1]:
        flag=-1
        break
    if flag == 0:
      print(c[0])
    else: 
      print(-1)

  if n == 2:
    for i in range(m):
      ans[s[i]-1]=c[i]
    for i in range(m):
      if ans[s[i]-1]!=c[i]:
        flag=-1
        break
    if ans[0] == 0:
      print(-1)
    elif flag == 0:
      print(ans[0]*10+ans[1])
    else: 
      print(-1)

  if n == 3:
    for i in range(m):
      ans[s[i]-1]=c[i]
    for i in range(m):
      if ans[s[i]-1]!=c[i]:
        flag=-1
        break
    if ans[0]==0:
      print(-1)
    elif flag == 0:
      print(ans[0]*100+ans[1]*10+ans[2])
    else: 
      print(-1)
else:
  if n == 1:
    print(0)
  elif n == 2:
    print(10)
  elif n == 3:
    print(100)