Harryxun/stf_run huggingface dataset:
# %%
N, M = list(map(int, input().split()))

# %%
A = list(map(lambda x: int(x), input().split(' ')))
A.sort()
A = A[::-1]

for _ in range(M):
    A[0] = A[0] // 2
    for i in range(N):
        if A[i+1] > A[i]:
            A[i+1], A[i] = A[i:i+2]
        else:
            break
    
print('{}'.format(sum(A)))

### FIXED CODE ###

import heapq
 
N, M = list(map(int, input().split()))
A = input().split(" ")
neg_A = [-int(a) for a in A]
 
heapq.heapify(neg_A)
 
for t in range(M):
    heapq.heappush(neg_A, -(-heapq.heappop(neg_A)//2))
print(-sum(neg_A))
x, y = map(int, input().split())
if x < y:
    print('<')
elif x > y:
    print('>')
else:
    print('=')


### FIXED CODE ###

x, y = input().split()
if x < y:
    print('<')
elif x > y:
    print('>')
else:
    print('=')
S = int(input())
K = int(input())

lst = []
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst[0])
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])

### FIXED CODE ###

S = int(input())
K = int(input())

lst = [0]*100
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst)
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])
a, b = map(int, raw???input() .split())

if a<b :
   print 'a<b'
elif a>b :
   print 'a>b'
elif a == b :
   print 'a==b'

### FIXED CODE ###

a, b = map(int, raw_input().split())
  
if a>b:
  print 'a > b'
elif a<b:
  print 'a < b'
elif a==b:
  print 'a == b'
lsnum = list(input())
lsnum1 = [int(i) for i in lsnum]
ls = ['+','-']
for i in ls:
    if i == '+':
        ans7 = lsnum1[0] + lsnum1[1]
    else:
        ans7 = lsnum1[0] - lsnum1[1]
    for j in ls:
        if j == '+':
            ans7 += lsnum1[2]
        else:
            ans7 -= lsnum1[2]
        for k in ls:
            if k == '+':
                ans7 += lsnum1[3]
            else:
                ans7 -= lsnum1[3]
            if ans7 == 7:
                ans = lsnum[0]+i+lsnum[1]+j+lsnum[2]+k+lsnum[3]+'=7'
                break
print(ans)

### FIXED CODE ###

lsnum = list(input())
lsnum1 = [int(i) for i in lsnum]
ls = ['+','-']
for i in range(2 ** 3):
    ans = lsnum1[0]
    for j in range(3):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
           ans += lsnum1[j+1]
        else:
            ans -= lsnum1[j+1]
    if ans == 7:
        bit = i
        break
ans2 = lsnum[0]
for i in range(3):
    if ((bit >> i) & 1):
        ans2 += '+'+lsnum[i+1]
    else:
        ans2 += '-'+lsnum[i+1]
print(ans2+'=7')
a,b,k=map(int,input().split())
if a=k:
  print(a-a,b)
  
elif a>k:
  print(a-k,b)
  
else:
  print(a-a,b+a-k)
  
  


### FIXED CODE ###

a,b,k=map(int,input().split())
if a>=k:
  print(a-k,b)
  
else:
  print(0,max(0,a+b-k))
import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  if p < n-2:
    m = min(dp(p+1)+abs(h[p]-h[p+1]), dp(p+2)+abs(h[p]-h[p+2]))
    d[p] = m
    return m
  if p == n-2:
    return dp(p+1)+abs(h[p]-h[p+1])

print(dp(0, 0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  if p < n-2:
    m = min(dp(p+1)+abs(h[p]-h[p+1]), dp(p+2)+abs(h[p]-h[p+2]))
    d[p] = m
    return m
  if p == n-2:
    return dp(p+1)+abs(h[p]-h[p+1])

print(dp(0))
a, b = [int(i) in input().split(" ")]

print(int(a/b), a%b, float(a/b), sep = " ")

### FIXED CODE ###

a, b = [int(i) for i in input().split(" ")]
num1 = a // b
num2 = a % b
num3 = "{:.8f}".format(a / b)

print(num1, num2, num3)
#
# abc049 c
#
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

while len(s) > 0:
    flag = 0
    for w in words:
        if s[-1 * len(w):] == w:
            s = s.replace(w, "").rstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES"

### FIXED CODE ###

#
# abc049 c
#
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

s = s[::-1]
while len(s) > 0:
    flag = 0
    for w in words:
        w = w[::-1]
        if s[0:len(w)] == w:
            s = s[len(w)::]
            # s = s.replace(w, "").lstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES")
s = input()
k = int(input())
infinity = 5 * (10 ** 11) - 1

import math

i = 0
while k > 0:
  k -= math.floor(infinity * math.log(int(s[i]), 10)) + 1
  i += 1
  
print(s[i-1])

### FIXED CODE ###

s = input()
k = int(input())

for i in map(int, s[:k]):
  if i != 1:
    print(i)
    break
else:
  print(1)
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
num = {i:s.count(i) for i in set(s)}
out = [v-max(0,t.count(k)) for k, v in num.items()]
print(max(out,0))

### FIXED CODE ###

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
num = {i:s.count(i) for i in set(s)}
out = [v-max(0,t.count(k)) for k, v in num.items()]
print(max(max(out),0))
import bisect
s=input()
s=input().split()
t=input()
t=input().split()
s.sort()
t.sort()
f=False
for c in t:
 i=bisect.bisect_left(s,c)
 if s[i]!=c:
  print("NO")
  f=True
  break
 else:
  s.pop[i]
if not f:
 print("YES")

### FIXED CODE ###

lena=int(input())
s=input().split()
a=[]
for i in s:
 a.append(int(i))
a.sort()
lenb=int(input())
s=input().split()
b=[]
for i in s:
 b.append(int(i))
b.sort()
i=0
j=0
while i<lena:
    if a[i]==b[j]:
        i+=1
        j+=1
        if j==lenb:
            break
    elif a[i]<b[j]:
        i+=1
    else:
        break
if j==lenb:
    print("YES")
else:
    print("NO")
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))
BC = sorted(BC, reverse=True, key=lambda x:x[1])

first_idx = 0
last_idx = 0
for num, val in BC:
    if A[last_idx] >= val:
        break
    
    for _ in range(num):
        if last_idx >= N:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            break

        if A[last_idx] < val:
            last_idx += 1
        else:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            first_idx = last_idx
            break

        
    else:
        A[first_idx:last_idx] = [val] * (last_idx - first_idx)
        first_idx = last_idx

print(sum(A))

### FIXED CODE ###

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))
BC = sorted(BC, reverse=True, key=lambda x:x[1])

first_idx = 0
last_idx = 0
for num, val in BC:
    if last_idx >= N:
        break

    if A[last_idx] >= val:
        break
    

    for _ in range(num):
        if A[last_idx] < val:
            last_idx += 1
        else:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            first_idx = last_idx
            break

        if last_idx >= N:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            break
    else:
        A[first_idx:last_idx] = [val] * (last_idx - first_idx)
        first_idx = last_idx

print(sum(A))
a = list(map(int,input().split()))
op = a[1]

if op == "+":
  print(a[0]+a[2])
else:
  print(a[0]-a[2])

### FIXED CODE ###

a,o,b=input().split()
a=int(a)
b=int(b)
print(a+b if o=="+" else a-b)
S = input()
T = input()
if S == T or S.reverse == T:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

S = input()
T = input()
for i in range(len(S)):
    if S == T:
        print("Yes")
        exit()
    else:
        S = S[-1]+S[:-1]
print("No")
from collections import deque
n, m = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    connect[a].append(b)
    connect[b].append(a)

color = [-1]*n
color[0] = 0
explored = {0}
next = deque(connect[0])
exploring =deque()
Yes = True
explored.add(0)
while next:
    now = next.popleft()
    exploring.extend(connect[now])
    while exploring:
        a = exploring.popleft()
        if color[a] == -1:
            color[a]=(color[now]+1)%2
        elif color[a] == (color[now]+1)%2:
            pass
        else:
            Yes = False
        if a not in explored:
            next.append(a)
        explored.add(a)
if -1 in color and Yes:
    fjasodjasodg


if Yes:
    s=sum(color)
    print(s*(n-s)-m)
else:
    print(n*(n-1)//2-m)

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    connect[a].append(b)
    connect[b].append(a)

color = [-1]*n
color[0] = 0
explored = {0}
next = deque([0])
exploring =deque()
Yes = True
explored.add(0)
while next:
    now = next.popleft()
    for a in connect[now]:
        if color[a] != -1:
            if color[a] != (color[now]+1)%2:
                Yes = False
            continue
        color[a] = (color[now]+1)%2
        next.append(a)
        
        
    '''
    exploring.extend(connect[now])
    while exploring:
        a = exploring.popleft()
        if color[a] == -1:
            color[a]=(color[now]+1)%2
        elif color[a] == (color[now]+1)%2:
            pass
        else:
            Yes = False
        if a not in explored:
            next.append(a)
        explored.add(a)
        '''
if Yes:
    s=sum(color)
    print(s*(n-s)-m)
else:
    print(n*(n-1)//2-m)
N, K =map(int,input().split())
x = list(map(int,input().split()))
a = 0
for i in range(100000):
    if x[i] >= 0:
        a = i
        break
s = x[a+K-1]
#print(K,s)
if a == 0:
    print(s)
else:
    for i in range(1, K):
        s = min(s,x[a+K-1-i]-x[a-i]+min(x[a+K-1-i],-x[a-i]))
    print(s)


### FIXED CODE ###

N, K = map(int, input().split())
x = list(map(int, input().split()))
m = float("INF")
for i in range(N - K + 1):
    if x[i + K - 1] * x[i] < 0:
        m = min(m, x[i + K - 1] - x[i] + min(abs(x[i + K - 1]), abs(x[i])))
    else:
        m = min(m, max(abs(x[i + K - 1]), abs(x[i])))
print(m)
from functools import reduce

N, M, X, Y = tuple(map(int, input().split()))
want_X = [int(x) for x in inut().split()]
want_Y = [int(x) for x in inut().split()]

print('No War' if max(want_X + X) < min(want_Y + Y) else 'War')


### FIXED CODE ###

N, M, X, Y = tuple(map(int, input().split()))
area_X = [int(x) for x in input().split()]
area_Y = [int(x) for x in input().split()]
area_X.append(X)
area_Y.append(Y)

print('No War' if max(area_X) < min(area_Y) else 'War')
inputted = list(map(int, input().split()))
A = inputted[0]
B = inputted[1]
K = inputted[2]

A2 = max([0, A - K])
B2 = max([0, B - max([0, K - A]))

answer = '{} {}'.format(A2, B2)

print(answer)


### FIXED CODE ###

inputted = list(map(int, input().split()))
A = inputted[0]
B = inputted[1]
K = inputted[2]

A2 = max([0, A - K])
B2 = max([0, B - max([0, K - A])])

answer = '{} {}'.format(A2, B2)

print(answer)
a = int(input)

ans = a + a**2 + a**3

print(ans)

### FIXED CODE ###

a = int(input())

ans = a + a**2 + a**3

print(ans)
#!/usr/bin/env python3
from collections import defaultdict, deque

H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
grid = [list(map(int, input().split())) for _ in range(H)]

d = defaultdict(lambda: float("inf"))
d["1_1"] = 0
nums = [i for i in range(10) if i != 1]

q = deque([[[1], 0]])

while q:
    tmp = q.pop()
    num, cost = tmp[0], tmp[1]
    if len(num) > 1:
        key = str(num[-1]) + "_1"
        d[key] = min(d[key], cost)
    if len(num) < 10:
        for n in nums:
            num_tmp = num.copy()
            if n not in set(num_tmp):
                num_tmp.append(n)
                q.append([num_tmp, cost + c[n][num_tmp[-2]]])

ans = 0
for i in range(H):
    for j in range(W):
        tmp = grid[i - 1][j - 1] 
        if tmp >= 0:
            ans += d[str(tmp) + "_1"]
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import copy

H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
grid = [list(map(int, input().split())) for _ in range(H)]

d = dict()
nums = [i for i in range(10) if i != 1]
d["-1_1"] = 0

q = [[[1], 0]]

while q:
    tmp = q.pop()
    num, cost = tmp[0], tmp[1]
    key = str(num[-1]) + "_1"
    if d.get(key):
        d[key] = min(d[key], cost)
    else:
        d[key] = cost
    if len(num) < 10:
        for n in nums:
            num_tmp = copy.copy(num)
            if n not in set(num_tmp):
                num_tmp.append(n)
                q.append([num_tmp, cost + c[num_tmp[-1]][num_tmp[-2]]])

ans = 0
for i in range(H):
    for j in range(W):
        tmp = grid[i - 1][j - 1] 
        ans += d[str(tmp) + "_1"]
print(ans)
import fractions
import functools
 
def main():
    n = int(input())
    a = [int(t)for t in input().split()]
 
    a_gcd = functools.reduce(fractions.gcd,a)
  
  	a = [x//a_gcd for x in a]
    gcdlist = []
 
    for i in range(n):
        t = [x for x in a]
        del t[i]
        t_gcd = functools.reduce(fractions.gcd,t)
        gcdlist.append(t_gcd)
 
    print(a_gcd*max(gcdlist))
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import fractions
import functools

def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    a_gcd = functools.reduce(fractions.gcd,a)
    a = [x//a_gcd for x in a]
    
    a_rev = a[::-1]

    lgcd = [0]
    rgcd = [0]
    for i in range(n):
        l = fractions.gcd(a[i],lgcd[i])
        r = fractions.gcd(a_rev[i],rgcd[i])
        lgcd.append(l)
        rgcd.append(r)

    rgcd = rgcd[::-1]
    g = [fractions.gcd(lgcd[i],rgcd[i+1]) for i in range(n)]
    
    print(max(g)*a_gcd)
    
    
if __name__ == "__main__":
    main()
import math


#vector的なやつ
#a=[input() for in range(n)]

n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis+=(x[i][k]-x[j][k])**2
        if is_integer(sqrt(dis)):
            cnt+=1
print(cnt)


### FIXED CODE ###

import math

n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis+=(x[i][k]-x[j][k])**2
        if math.sqrt(dis)%1==0:
            cnt+=1
print(cnt)
n = int(input())
L = [int(i) for i in input().split()]
L.sort()

def out_detect(n,L):
  flag = 0
  if n%2 == 0:
    for i in range(n):
      if L[i] != -(-(i+1)//2)*2-1:
        flag = 1
        break
  else:
    if L[0] != 0:
      flag = 1
      return (flag)
    for i in range(1,n):
      if L[i] != (-(-i//2)*2):
        flag = 1
        break
  return (flag)

if out_detect(n,L) == 1:
  print(0)
else:
  if n%2 == 0:
    out = pow(2,n//2)
  else:
    out = pow(2,(n-1)//2)
print(out%(pow(10,9)+7))

### FIXED CODE ###

n = int(input())
L = [int(i) for i in input().split()]
L.sort()

def out_detect(n,L):
  flag = 0
  if n%2 == 0:
    for i in range(n):
      if L[i] != -(-(i+1)//2)*2-1:
        flag = 1
        break
  else:
    if L[0] != 0:
      flag = 1
      return (flag)
    for i in range(1,n):
      if L[i] != (-(-i//2)*2):
        flag = 1
        break
  return (flag)

if out_detect(n,L) == 1:
  print(0)
else:
  if n%2 == 0:
    out = pow(2,n//2)
  else:
    out = pow(2,(n-1)//2)
  print(out%(pow(10,9)+7))
n = int(input())
s = input()
 
if n%2 == 1:
  print("No")

slise = (n/2)*1
a = s[:int(start)]
b = s[int(slise):]

if a==b:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import sys

n = int(input())
s = input()
 
if n%2 == 1:
  print("No")
  sys.exit()
 
slise = (n/2)
a = s[:int(slise)]
b = s[int(slise):]
 
if a==b:
  print("Yes")
else:
  print("No")
def merge(A, left, mid, right):
    global cnt
    inf = 500000001
    n1, n2 = mid - left, right - mid
    L, R = A[left:left+n1]+[inf], A[mid:mid+n2]+[inf]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

cnt = 0
n = int(input())
A = list(map(int, input().strip().split()))
mergeSort(A, 0, n)
print(*A)
print(cnt)

### FIXED CODE ###

def merge(A, left, mid, right):
    global cnt
    inf = 100000000001
    n1, n2 = mid - left, right - mid
    L, R = A[left:left+n1]+[inf], A[mid:mid+n2]+[inf]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

cnt = 0
n = int(input())
A = list(map(int, input().strip().split()))
mergeSort(A, 0, n)
print(*A)
print(cnt)
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[N-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in reversed(range(N-1)):
        e[i] = max(e[i+i], A[i])

    for i in range(N):
        if i == 0:
            print(e[i+1])
        elif i == N-1:
            print(s[i-1])
        else:
            print(max(s[i-1], e[i+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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    ml = A.copy()
    ml.sort(reverse=True)

    Am = ml[0]
    As = ml[1]

    for i in range(N):
        if(A[i] == Am):
            print(As)
        else:
            print(Am)
    

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
A, B, C = map(int, input().split())
if A % B == 0:
    if C == 0:
        print('YES')
    else:
        print('NO')
elif A > B:
    if C % (A % B) == 0 or (B - C) % (A % B) == 0:
        print('YES')
    else:
        print('NO')
else:
    if C % (B - A) == 0 or (B - C) % A == 0 or (B - C) % (B % A):
        print('YES')
    else:
        print('NO')

### FIXED CODE ###

A, B, C = input().split()
print('YES' if A[-1]==B[0] and B[-1]==C[0] else 'NO')
S,W=map(unt,input().split())
if S>W:
  print("safe")
else:
  print("unsafe")

### FIXED CODE ###

s,w=map(int,input().split())
if s > w:
  print("safe")
else:
  print("unsafe")
import sys
n,m,k =map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = k
i = 0
asum = [0]* n
bsum = [0]* m
suma = 0
sumb = 0
j =0
for  i in a:
    suma += i
    asum[j]= suma
    j +=1
j =0
for  i in b:
    sumb += i
    bsum[j] = sumb
    j +=0

count = 1
ans = 1

for j in range(m + n-1):
    count = 0
    for i in range(ans):
        if asum[ans-1]+bsum[ans]<=k:
            count = 1

    if count ==1:
        ans +=1
    else:
        break
print(min(ans,m+n))

### FIXED CODE ###

import sys
n,m,k =map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = k
i = 0
asum = [0]* (n+1)
bsum = [0]* (m+1)
suma = 0
sumb = 0

for  i in range(n):
    suma += a[i]
    asum[i+1]= suma


for  i in range(m):
    sumb += b[i]
    bsum[i+1] = sumb

count = 1
ans = 0

for i in range(n+1):
    if ans < i :
        if asum[i] <= k:
            ans=i
    else:
        for j in range(ans-i,m+1,1):
            if asum[i] + bsum[j]<=k:
                if i+j>ans:
                    ans=i+j
            else:
                break

print(min(ans,m+n))
N = int(input())
A = list(map(int,input().split()))
money = 1000
cab = 0
lowprice = A[0]
check = True
for i in range(1,N):
    if(lowprice>A[i]):
        lowprice = A[i]
        check= True
    elif(lowprice<A[i] and check == True):
        high_price = A[i]
        if(i<=N-1):
            if(high_price > A[i+1]):
                cab=money//lowprice
                money-=(lowprice*cab)
                money+=(high_price*cab)
                cab = 0
                check = False
                lowprice = high_price
        else:
            cab=money//lowprice
            money-=(lowprice*cab)
            money+=(high_price*cab)
            cab = 0
            check = False
            lowprice = high_price


print(money)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
money = 1000
cab = 0
lowprice = A[0]
check = True
for i in range(1,N):
    if(lowprice>A[i]):
        lowprice = A[i]
        check= True
    elif((lowprice<A[i]) and (check == True)):
        high_price = A[i]
        if(i<N-1):
            if(high_price > A[i+1]):
                cab=money//lowprice
                money-=(lowprice*cab)
                money+=(high_price*cab)
                cab = 0
                check = False
                lowprice = high_price
        else:
            cab=money//lowprice
            money-=(lowprice*cab)
            money+=(high_price*cab)
            cab = 0
            check = False
            lowprice = high_price
print(money)
ab = input()
a, b = ab.split(" ")
A = int(a)
B = int(b)

if "0" in a or "0" in b or a > 9 or b > 9:
    print(-1)
else:
    print(A * B)

### FIXED CODE ###

ab = input()
a, b = ab.split(" ")
A = int(a)
B = int(b)

if "0" in a or "0" in b or A > 9 or B > 9:
    print(-1)
else:
    print(A * B)
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for i in range(M)]
a = 0
for i in range(M):
    if SC[i][0] != N or (SC[i][0] ==3 and SC[i][1]==0):
        a += 1

handred = 0
ten = 0
one = 0

for i in range(M):
    if S[i][0] == 3:
        handred = 9
    elif S[i][0] == 2:
        ten = 9
    elif S[i][0] == 1:
        one = 9

if a == M:
    print('-1')
else:
    for i in range(M):
        if S[i][0] == 3:
            if handred >= S[i][1]:
                handred = S[i][1]
        elif S[i][0] == 2:
            if ten >= S[i][1]:
                ten = S[i][1]
        elif S[i][0] == 1:
            if one >= S[i][1]:
                one = S[i][1]

if a != M and N == 3:
    print(str(handred) + str(ten) + str(one))
elif a != M and N == 2:
    print(str(ten) + str(one))
elif a != M and N==1:
    print(str(one))

### FIXED CODE ###

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
for i in range(10**N): #rangeで書けば小さい順に実行するのを利用
    if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in sc):
                    #iの桁数指定では、入力のsと一つずれることに注意  
                    #このif文では最小値である可能性のある数字がリスト中にあるかどうか確認
        print(i)
        break
else:
    print(-1)