Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
S = [0]*M
C = [0]*M
SC = {1: set([]), 2: set([]), 3: set([])}
for m in range(M):
    S[m], C[m] = map(int, input().split())
    SC[S[m]].add(C[m])

ANS = [0]*N
out = 0
for i in range(1, 4):
    if len(SC[i]) >= 2:
        out = 1
if out == 1:
    print(-1)

else:
    if N == 1:
        if len(SC[1]) == 0:
            ANS[0] = 0
        else:
            ANS[0] = list(SC[1])[0]

    else:
        for i in range(N):
            if i == 0:
                if list(SC[i+1])[0] == 0:
                    out = 1
                elif len(SC[i+1]) == 0:
                    ANS[0] == 1
                else:
                    ANS[0] = list(SC[i+1])[0]
            else:
                if len(SC[i+1]) == 0:
                    ANS[i] = 0
                else:
                    ANS[i] = list(SC[i+1])[0]
    if out == 1:
        print(-1)
    else:
        ans = 0
        for i in range(N):
            ans += ANS[i]*10**(N-i-1)
        print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
S = [0]*M
C = [0]*M
SC = {}
SC = {1: set([]), 2: set([]), 3: set([])}
for m in range(M):
    S[m], C[m] = map(int, input().split())
    SC[S[m]].add(C[m])

ANS = [0]*N
out = 0
for i in range(1, 4):
    if len(SC[i]) >= 2:
        out = 1
if out == 1:
    print(-1)

else:
    out = 0
    if N == 1:
        if len(SC[1]) == 0:
            ANS[0] = 0
        else:
            ANS[0] = list(SC[1])[0]

    else:
        for i in range(N):
            if i == 0:
                if len(SC[i+1]) == 0:
                    ANS[0] = 1
                elif list(SC[i+1])[0] == 0:
                    out = 1
                else:
                    ANS[0] = list(SC[i+1])[0]
            else:
                if len(SC[i+1]) == 0:
                    ANS[i] = 0
                else:
                    ANS[i] = list(SC[i+1])[0]
    if out == 1:
        print(-1)
    else:
        ans = 0
        for i in range(N):
            ans += ANS[i]*10**(N-i-1)
        print(ans)
from collections import Counter
n = int(input())
c = input()
s = Counter(c)
if s['W'] == 0:
  print('0')
elif c.index('R') == 0 and c.index('W') == s['R']:
  print('0')
elif s['R'] > c.index('R'):
  print(s['R'] - (c.index('R')+1) + c.index('R'))
else:
  print(s['R'])

### FIXED CODE ###

import sys
from collections import Counter
n = int(input())
c = list(input())
s = Counter(c)
if s['R'] == 0 or s['W'] == 0:
  print('0')
  sys.exit()
pos_w=0
pos_r=n-1
count = 0
for i in range(pos_w, n):
  if c[i] != 'W':
    continue
  pos_w = i
  for j in range(pos_r, -1, -1):
    if c[j] != 'R':
      continue
    pos_r = j
    if pos_w > pos_r:
      print(count)
      sys.exit()
    c[i] = 'R'
    c[j] = 'W'
    count += 1
    break
n = int(input())
A = list(map(int,input().split()))

b = 1
B=[0]*(n+1)
count = 0
for i in range(n):
    B[i] = b
    if 2*(b - A[i]) < A[i+1]:
        count += 1
    b = 2*(b - A[i])

B[n] = b

j = 0
while A[n] > B[j]:
    j+=1
    print(j,A[n],B[j])

total = 0
for i in range(j):
    total += B[i]

print(total)
s = A[n]
for i in range(n-1,j-1,-1):
    total += min(B[i],s+A[i])
    print(B[i],s+A[i])
    s+=A[i]

if count==0:
    print(total+A[n])
else:
    print('-1')

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))

b = 1
B=[0]*(n+1)
count = 0

t=len(A)-1
for i in range(t):
    B[i] = b
    if 2*(b - A[i]) < A[i+1]:
        count += 1
        break
    b = 2*(b - A[i])
B[n] = b

if n == 0 and A[0] > 1:
    count += 1

j = 0
while count == 0 and A[t] > B[j]:
    if j == n:
        break
    j += 1

total = 0
for i in range(j):
    total += B[i]

s = A[t]
for i in range(t-1,j-1,-1):
    total += min(B[i],s+A[i])
    s+=A[i]

if count==0:
    print(total+A[t])
else:
    print('-1')
a = input()

if int(a[6:8])<=4:
  print("Heisei")
else:
  print("TBD")

### FIXED CODE ###

a = input()

if int(a[5:7])<=4:
  print("Heisei")
else:
  print("TBD")
a, b, c = input().split()
if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
 print(’YES’)
else:
 print(’NO’)


### FIXED CODE ###

a, b, c = input().split()

if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
	print("YES")
else:
	print("NO")
#!/usr/bin/env python3

def main():
    A, B = map(int, open(0).read().split())

    ans_A = []
    for i in range(int(12.5 * A), int(12.5 * A + 12.5 + 1)):
        ans_A.append(i)
    ans_B = []
    for i in range(int(10*B), int(10*B + 10 + 1)):
        ans_B.append(i)
    ans = set(ans_A) & set(ans_B)
    if len(ans) == 0:
        print(-1)
    else:
        print(min(list(ans)))


main()

### FIXED CODE ###

#!/usr/bin/env python3

def main():
    *S, = map(str, open(0).read().split())
    S = S[0]
    if (S == "AAA" or S == "BBB"):
        print("No")
    else:
        print("Yes")


main()
N = int(input())
X = list(map(int,input().split()))
import math
ans = 0
mod = 10**9+7
a = 0
ans = 0
for i in range(N-1):
  a += (1/(i+1))*math.factorial(N-1)
  ans += (X[i+1]-X[i]%mod)*(a%mod)

print(int(ans)%mod)

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
import math
ans = 0
mod = 10**9+7
a = 0
ans = 0
for i in range(N-1):
  a += pow(i+1,mod-2,mod)
  ans += ((X[i+1]-X[i])%mod)*(a%mod)
  ans %= mod
  
ans *= math.factorial(N-1)%mod

print(ans%mod)
a = input()

st = str(a)


if st[1:4] == "000":
  print(0)

else:
  z = st[1:4]
  print(1000 - int(z))


### FIXED CODE ###

a = input()

st = str(a)


if st[-3:] == "000":
  print(0)


else:
  z = st[-3:]
  print(1000 - int(z))
import math

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)
    tA = []
    for a in A:
        tA.append((a, 1))

    for k in range(K):
        print('rope:' + str(k))
        a, diva = tA[1]
        b, divb = tA[0]
        print(tA)
        while b/divb > a/diva:
            divb += 1
        B = b/divb
        x = 1
        while x < N:
            xn, divx = tA[x]
            if xn/divx < B:
                break
            x += 1
        if x != N:
            tA.insert(x, (b, divb))
        else:
            tA.append((b, divb))
        tA = tA[1:]
        print(tA)
    print(math.ceil(tA[0][0]/tA[0][1]))


if __name__ == '__main__':
    main()



### FIXED CODE ###

from math import ceil


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    def check(Min):
        kill = 0
        for a in A:
            kill += (ceil(a/Min)-1)
        return kill <= K

    l = 0
    r = 1000000000

    while r-l > 1:
        mid = (l+r)//2
        if check(mid):
            r = mid
        else:
            l = mid
    print(r)
        


if __name__ == '__main__':
    main()
import sys

n=sys.stdin.readline().rstrip()[::-1]
to=0
num=len(n)
m=0

for i in range(num):
    k=int(n[i])
    k+=m
    if k==5:
        if int(n[i+1])>=5:
            to+=10-k
            m=1
        else:
            to+=k
            m=0
    if k<5:
        to+=k
        m=0
    elif k>5:
        to+=10-k
        m=1
        
print(to+m)


### FIXED CODE ###

import sys

n=sys.stdin.readline().rstrip()[::-1]
to=0

m=0
n+="0"
num=len(n)

for i in range(num):
    k=int(n[i])
    k+=m
    if k==5:
        if int(n[i+1])>=5:
            to+=10-k
            m=1
        else:
            to+=k
            m=0
    if k<5:
        to+=k
        m=0
    elif k>5:
        to+=10-k
        m=1
        
print(to+m)
s=input()
print(s[:-8]

### FIXED CODE ###

s=input()
print(s[:-8])
h, w, a, b = map(int,input().split())
for i in range(h):
  if i < b:
    print("1"a+"0"*(w-a))
  else:
    print("0"a+"1"*(w-a))

### FIXED CODE ###

h,w,a,b=map(int,input().split())
for i in range(h):
    if i<b:
        print("1"*a+"0"*(w-a))
    else:
        print("0"*a+"1"*(w-a))
from fractions import Fraction
num = int(input())
l=[]
for i in range(num):
    k=int(input())
    x=Fraction(1, k)
    l.append(x)
p=sum(l)
y=int(1/p)
print(y)

### FIXED CODE ###

a = int(input())
l=list(map(int ,input().split()))
ll=[]
for i in range(a):
        j=1/l[i]
        ll.append(j)
k=sum(ll)
print(1/k)
import sys
input = sys.stdin.readline
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = list(input().strip())
Q = int(input().strip())
cbt = dict()
MX = 10**5
for c in aas:
    cbt[c] = Bit(MX)
    for i, a in enumerate(S):
        if a == c:
            cbt[c].add(i+1, 1)

for _ in range(Q):
    t, i, c = input().split()
    t = int(t)
    if t == 1:
        i = int(i)
        if S[i-1] != c:
            cbt[S[i-1]].add(i, -1)
            cbt[c].add(i, 1)
            S[i-1] = c
    else:
        l, r = int(i), int(c)
        s = 0
        for a in aas:
            bt = cbt[a]
            s += (bt.sum(r+1)-bt.sum(l-1)>0)
        print(s)


### FIXED CODE ###

import sys
input = sys.stdin.readline
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = list(input().strip())
Q = int(input().strip())
cbt = dict()
MX = 5 * 10**5 + 2
for c in aas:
    cbt[c] = Bit(MX)
    for i, a in enumerate(S):
        if a == c:
            cbt[c].add(i+1, 1)

for _ in range(Q):
    t, i, c = input().split()
    t = int(t)
    if t == 1:
        i = int(i)
        if S[i-1] != c:
            cbt[S[i-1]].add(i, -1)
            cbt[c].add(i, 1)
            S[i-1] = c
    else:
#        print(S)
        l, r = int(i), int(c)
#        print(l, r)
        s = 0
        for a in aas:
            bt = cbt[a]
#            print(a, bt.sum(r),bt.sum(l-1))
            s += (bt.sum(r)-bt.sum(l-1)>0)
        print(s)
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = [i for i, x in enumerate(a) if x == b[0]] #最大値の位置

for i in range(n):
    if a[i] == b[0]: #最大値だったら
        print(b[1]) #最大値から2番目を出力
    else: #そうでなければ
        print(b[0]) #最大値を出力

### FIXED CODE ###

import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = a.count(b[0])

if len(b) == 1 or c > 1: #bの長さが1または、最大値が2回以上存在するなら
    for i in range(n):
        print(b[0]) #最大値のみを表示

else: #bの長さが2以上なら
    for i in range(n):
        if a[i] == b[0]: #i番目が最大値だったら
            print(b[1]) #2番目に大きい値を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

if "T" not in s:
	x_list = [len(s)]
	y_list = []
else:
	F = s.split("T")

	x_list = []
	y_list = []
	for i, n in enumerate(F):
		if i%2 == 0:  # x軸方向
			x_list.append(len(n))
		else:
			y_list.append(len(n))

"""
x_listから順に取り出して右か左に動く．
dp[i][x] := i回目の移動後にx座標がxとなっていることができるか
y軸も同様
"""

x -= x_list.pop(0)  # 最初のFの分だけ右に動く
x_sum = sum(x_list)
y_sum = sum(y_list)


if (x_sum-x)%2 != 0:  # パリティ
  print("No")
  sys.exit()
else:
  n_x = (x_sum-abs(x))//2
if (y_sum-y)%2 != 0:
  print("No")
  sys.exit()
else:
  n_y = (y_sum-abs(y))//2

dp_x = [[False]*(abs(n_x)+1) for _ in range(len(x_list)+1)]
dp_y = [[False]*(abs(n_y)+1) for _ in range(len(x_list)+1)]
dp_x[0][0] = True
dp_y[0][0] = True

for i in range(1, len(x_list)+1):
	for j in range(n_x+1):
		if dp_x[i-1][j]:
			dp_x[i][j] = True
			if j+x_list[i-1] < n_x+1:
				dp_x[i][j+x_list[i-1]] = True

for i in range(1, len(y_list)+1):
	for j in range(n_y+1):
		if dp_y[i-1][j]:
			dp_y[i][j] = True
			if j+y_list[i-1] < n_y+1:
				dp_y[i][j+y_list[i-1]] = True

if dp_x[-1][-1] and dp_y[-1][-1]:
	print("Yes")
else:
	print("No")


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

x_list = []
y_list = []
for i, s_ in enumerate(s.split('T')):
	if i == 0:
		x -= len(s_)
	elif i % 2 == 0:
		x_list.append(len(s_))
	else:
		y_list.append(len(s_))

def check(d, x):
  se =set([0])
  for dx in d:
    se={a+b for a,b in product(se,[-dx,dx])}  # 直積としてDPを計算
  return (x in se)

print('Yes' if check(x_list, x) and check(y_list, y) else 'No')
S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  if S[0] == 'R':
    ans += S[1:].count('B') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='R' and S[j+1] !='R':
          ans-=1
      except:
        pass
  if S[0] == 'B':
    ans += S[1:].count('R') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='B' and S[j+1] !='B':
          ans-=1
      except:
        pass
  if S[0] == 'G':
    ans += S[1:].count('B') * S[1:].count('R')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='G' and S[j+1] !='G':
          ans-=1
      except:
        pass
  S  = S[1:]
print(ans)

### FIXED CODE ###

a = input()

b = 0
for i in a:
  if i == '7':
    print('Yes')
    break
  b+=1
  if b == 3:
    print('No')
A,B = input().split()
A = int(A) 
B = float(B)
B = "{:.2f}".format(B)
#print(int(A*B))
print(int(A*B))

### FIXED CODE ###

import math
from decimal import *
a,b = map(float,input().split())
ans = Decimal(str(b))*int(a)
print(math.floor(ans))
(n, m) = [int(i) for i in input().split()]

A = [[]]
b = []


for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    b.append(int(input()))


for i in range(n):
    c = 0

    for j in range(m):
         c += A[i][j] * b[j]

    print(c)

### FIXED CODE ###

(n, m) = [int(i) for i in input().split()]

A = []
b = []


for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    b.append(int(input()))


for i in range(n):
    c = 0

    for j in range(m):
         c += A[i][j] * b[j]

    print(c)
a,b,c,d=map(int,input().split())
e=0
f=0
while a-d>=0:
    g=a-d
    e+=1
    a=g
while c-b>=0:
    h=c-b
    f+=1
    c=h
if g<h:
    print('Yes')
elif f==0:
    print('Yes')
elif e==f:
    print('No')
else:
    print('No')
    


### FIXED CODE ###

import math
a,b,c,d=map(int,input().split())
e=math.ceil(c/b)
f=math.ceil(a/d)
if e>f:
  print('No')
elif e==f:
  print('Yes')
else:
  print('Yes')
N,M = map(int,input().split())
INFTY = 10**10
A = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[0])
hist = [0 for _ in range(N)]
dist = [-INFTY for _ in range(N)]
hist[A[0][0]]=1
dist[A[0][0]] = 0
hist[A[0][1]]=1
dist[A[0][1]] = dist[A[0][0]]+A[0][2]
flag = 0
for j in range(1,M):
    ind = A[i][0]
    ind2 = A[i][1]
    if hist[ind]==1:
        if hist[ind2]==1:
            if dist[ind2]==dist[ind]+A[i][2]:
                continue
            else:
                flag = 1
                break
        else:
            dist[ind2] = dist[ind]+A[i][2]
            hist[ind2] = 1
    else:
        if hist[ind2]==1:
            dist[ind] = dist[ind2]-A[i][2]
            hist[ind]=1
        else:
            dist[ind] = 0
            hist[ind] = 1
            dist[ind2] = A[i][2]
            hist[ind2]=1
if flag==0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

from collections import deque
INFTY = 10**10
N,M = map(int,input().split())
ind = 2
if N==1:
    ind = 0
else:
    G = {}
    for _ in range(M):
        L,R,D = map(int,input().split())
        if L not in G:
            G[L]=[]
        G[L].append((R,D))
        if R not in G:
            G[R] = []
        G[R].append((L,-D))
    dist = [INFTY for _ in range(N+1)]
    hist = [0 for _ in range(N+1)]
    for i in G:
        ind = 2
        heap = deque([i])
        while heap:
            cur = heap.popleft()
            if hist[cur]==0:
                dist[cur] = 0
                hist[cur]=1
                ind = 0
            elif hist[cur]==1 and ind==2:
                break
            for x in G[cur]:
                v,w = x[0],x[1]
                if hist[v]==0:
                    dist[v] = dist[cur]+w
                    heap.append(v)
                    hist[v]=1
                else:
                    if dist[v]!=dist[cur]+w:
                        ind = 1
                        break
            if ind==1:break
        if ind==1:break
if ind!=1:
    print("Yes")
else:
    print("No")
S = input()
Ans =[]
dic = ["A","T","G","C"]
rmp =""
for i in range(len(S)):
  if S[i] in dic:
    rmp += S[i]
  else:
    Ans.append(len(rmp))
    rmp = ""
print(max(Ans))

### FIXED CODE ###

S = input()
S=S.replace("T","A")
S=S.replace("G","A")
S=S.replace("C","A")
for i in range(10,-1,-1):
  if S.find("A"*i) != -1:
    print(i)
    break
import fraction
from functools import reduce
n=int(input())
A=list(map(int,input().split()))
def gcd(*numbers):
    return reduce(fraction.gcd,numbers)
print(gcd(*A))


### FIXED CODE ###

import fractions
from functools import reduce
n=int(input())
A=list(map(int,input().split()))
def gcd(*numbers):
    return reduce(fractions.gcd,numbers)
print(gcd(*A))
n = int(input())

if "7" in n:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

n = input()

if "7" in n:
    print("Yes")
else:
    print("No")
from collections import Counter
h, w = map(int, input().split())
A = []
for i in range(h):
    A.extend(list(input()))
cA = Counter(A)

l1 = h*w%2
l2 = (h//2)*(w%2) + (w//2)*(h%2)
l3 = (h//2)*(w//2)
if l1:
    for key, val in cA.items():
        if val%2==1:
            cA[key] -= 1
            break
for _ in range(l2):
    for key, val in cA.items():
        if val%4=-2:
            cA[key] -= 2
            break
print('Yes' if sum(val%4 for val in cA.values()) == 0 else 'No')

### FIXED CODE ###

from collections import Counter
h, w = map(int, input().split())
A = []
for i in range(h):
    A.extend(list(input()))
cA = Counter(A)

l1 = h*w%2
l2 = (h//2)*(w%2) + (w//2)*(h%2)
l3 = (h//2)*(w//2)
if l1:
    for key, val in cA.items():
        if val%2==1:
            cA[key] -= 1
            break
for _ in range(l2):
    for key, val in cA.items():
        if val%4==2:
            cA[key] -= 2
            break
print('Yes' if sum(val%4 for val in cA.values()) == 0 else 'No')
N,Y=map(int,input().split())
#N=a+b+c
#Y=10000*a+5000*b+1000*c
ans=[]
maxA=Y//10000
maxB=Y//5000
maxC=Y//1000
for a in range(maxA+1):
  for b in range(maxB+1):
    for c in range(maxC+1):
      if N==a+b+c:
        if Y==10000*a+5000*b+1000*c:
          ans.append(str(a)+" "+str(b)+" "+str(c))
if len(ans)!=0:
  print(ans[0])
else:
  print(str(-1)+" "+str(-1)+" "+str(-1))

### FIXED CODE ###

N=int(input())
d=set()
for i in range(N):
  d.add(int(input()))
print(len(d))
x=list(map(int,input().split()))

i=1
while i<=len(x):
    
    if x[i]==0:
        print(i)
    
    i+=1

### FIXED CODE ###

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

i=1
while i<=len(x):
    
    if x[i-1]==0:
        print(i)
    
    i+=1
if(input().rstrip() == 'ABC':
   print('ARC')
else:
   print('ABC')	

### FIXED CODE ###

if(input().rstrip() == 'ABC'):
    print('ARC')
else:
    print('ABC')
X = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

for i in range(len(make_divisors(X))):
    A = make_divisors(X)[i]
    for j in range(-63,118):
        if (A+j)**5-j**5==X:
            a = j + A
            b = j
            break
        else:
            continue
        break
    else:
        continue
    break
print(a,b)

### FIXED CODE ###

X = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

for i in range(len(make_divisors(X))):
    A = make_divisors(X)[i]
    for j in range(-64,119):
        if (A+j)**5-j**5==X:
            a = j + A
            b = j
            break
        else:
            continue
        break
    else:
        continue
    break
print(a,b)
def f(x):
  return x==x[::-1]
S=str(input())
N=len(S)
S1=S[:(N-3)/2]
S2=S[(N+1)/2:]
if f(S) and f(S1) and f(S2):
  print('Yes')
else:
  print('No')
  

### FIXED CODE ###

S=str(input())
def f(x):
  return x==x[::-1]
N=len(S)
S1=S[:(N-1)//2]
S2=S[(N+1)//2:]
if f(S) and f(S1) and f(S2):
  print('Yes')
else:
  print('No')
import math

a, b, x = map(int, input().split())

def calc_theta(a, b, x):
    tmp = (a ** 3) / (2 * (a **2 * b - x))
    tmp2 = (2 * x) / (a ** 2 * b)
    return 90 - math.degrees(math.atan(tmp)), 90 - math.degrees(math.atan(tmp2))

ans1, ans2 = calc_theta(a, b, x)

if ans2 > 45:
    print(ans2)
else:
    print(ans1)






### FIXED CODE ###

import math

a, b, x = map(int, input().split())

def calc_theta(a, b, x):
    if x >= 0.5 * a ** 2 * b:
        # tmp = (a ** 3) / (2 * ((a **2) * b - x)) これだと 0divになる
        tmp = (2/a)*(b-(x/a**2))
    else:
        tmp = (a * b * b) / (2 * x)
    return math.degrees(math.atan(tmp))

ans = calc_theta(a, b, x)

print('{:.10f}'.format(ans))
a=int(input())
b=a**a
print(int(a+b+a*b)

### FIXED CODE ###

a=int(input())
b=a*a
print(int(a+b+a*b))
def calc2(array):
    temp = []
    for x, y in zip(array[:-1], array[1:]):
        temp.append(abs(x-y))
    if len(temp) == 1:
        print(temp[0])
    else:
        calc2(temp)
def main():
    N = int(input())
    array = [0 for i in range(N+1)]
    s = input()
    for j in range(N):
        array[j+1] = int(s[j])
    calc2(array)
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    dp = [[10**5] * w for _ in range(h)]
    def func(temp, now, flag):
        x, y = now
        if y > h - 1 or x > w - 1:
            return 10**6
        if s[y][x] == "#":
            if not flag:
                temp += 1
            flag = True
        else:
            flag = False
        if x == w-1 and y == h-1:
            return temp
        if dp[y][x] <= temp:
            return 10**6
        dp[y][x] = temp
        piyo = []
        return min(func(temp, (x + 1, y), flag), func(temp, (x, y + 1), flag))
    print(func(0, (0, 0), False))
main()
a = input().split()
tg = a[0]
ok_nums = set("1","2","3","4","5","6","7","8","9","0")
ng_nums = set(input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
while True:
  if ok_nums >= set(d for d in str(i)):
    print(i)
    break
  else:
    i+=1
 

### FIXED CODE ###

a = input().split()
tg = a[0]
ok_nums = set(str(i) for i in range(10))
ng_nums = set(i for i in input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
intg = int(tg)
while intg > rt:
  if ok_nums >= set(d for d in str(i)):
    rt = i
  else:
    i+=1

print(rt)