CodeEff/ECCO huggingface dataset:
# Original solution
S, K = list(map(int, input().split()))
Bad = list(input().split())

while 1:
    if all(d not in str(S) for d in Bad):
        print(S)
        break
    S += 1


# Optimized solution
import sys
S, K = input().split()
Bad = list(map(int, input().split()))
OK = sorted(set(range(10)) - set(Bad))
NotZero = sorted(set(OK) - set([0]))

if any(d > str(OK[-1]) for d in S):
    print((str(NotZero[0]) + str(OK[0]) * len(S)))
    sys.exit()

count = [0] * 10
for c in str(S):
    count[ord(c) - ord('0')] += 1
greater = 0
ans = []


def can(i, d):
    c = str(d)
    if i == 0 and d == 0 and len(S) > 1:
        return 0
    if not greater and c < S[i]:
        return 0
    if c > S[i]:
        return 1
    for b in range(10):
        if count[b] > 0 and b > OK[-1]:
            return 0
    return 1

for i in range(len(S)):
    count[ord(S[i]) - ord('0')] -= 1
    for d in OK:
        if can(i, d):
            if str(d) > S[i]:
                greater = 1
            ans.append(d)
            break

print(("".join(str(a) for a in ans)))
# Original solution
def main():
    N, K = list(map(int, input().split()))
    D = input().split()

    for i in range(N, N*10):
        if len(set(list(str(i))) & set(D)) == 0:
            print(i)
            break

main()

# Optimized solution
n, k = list(map(int, input().split()))
d = [ int(x) for x in input().split() ]

def is_ok(x):
    while x != 0:
        if x % 10 in d:
            return False
        x //= 10
    return True

money = n
while True:
    if is_ok(n):
        print(n)
        break
    n += 1
# Original solution
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
nums = [i for i in range(10) if not i in l]

while True:
  total = 0
  for num in nums:
    total += list(str(n)).count(str(num))
  
  if total == len(list(str(n))):
    print(n)
    break
  
  n += 1

# Optimized solution
n, k = list(map(int, input().split()))
like = list(map(str, set(range(10)) - set(map(int, input().split()))))

while True:
  count = 0
  for c in str(n):
    if c in like:
      count += 1
      
  if count == len(str(n)):
    print(n)
    break
  
  n += 1
# Original solution
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)

def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero:
                                if 0 in [i,j,k,l,m] and i != 0:
                                    continue
                                elif 0 in [j,k,l,m] and j != 0:
                                    continue
                                if 0 in [k,l,m] and k != 0:
                                    continue
                                if 0 in [l,m] and l != 0:
                                    continue
                            print(money)
                            return

lowest()

# Optimized solution
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)

def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero:
                                if 0 in [i,j,k,l,m] and i != 0:
                                    continue
                                elif 0 in [j,k,l,m] and j != 0:
                                    continue
                                elif 0 in [k,l,m] and k != 0:
                                    continue
                                elif 0 in [l,m] and l != 0:
                                    continue
                            print(money)
                            return

lowest()
# Original solution
n,k = list(map(int,input().split()))
d = list(map(int,input().split()))
while 1:
    for c in str(n):
        if int(c) in d:
            break
    else:
        print(n)
        exit()
    n += 1


# Optimized solution
n,k=list(map(int,input().split()));d=input().split()
while 1:
    for c in str(n):
        if c in d:break
    else:
        print(n)
        exit()
    n += 1
# Original solution
from collections import deque

N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
like=list(range(1,10))
dislike0=False

for s in D:
    if s==0:
        dislike0=True
    else:
        like.remove(s)

like.sort()
q=deque(like)

if dislike0==False:
    like.insert(0,0)

while q:
    num=q.popleft()

    if num>=N:
        print(num)
        exit()
    for i in range(len(like)):
        q.append((int(str(num)+str(like[i]))))

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

while True:
    for s in str(N):
        if s in D:
            N+=1
            break
    else:
        print(N)
        exit()
# Original solution
n,k=list(map(int,input().split()))
d=list(map(int,input().split()))
a=[]
for i in range(10):
    sum=0
    for x in d:
        if x==i:
            break
        else:
            sum+=1
    if sum==k:
        a.append(i)
a=set(a)
for i in range(n,10*n+1):
    b=[]
    x=len(str(i))
    y=str(i)
    for j in range(x):
        b.append(int(y[j]))
    b=set(b)
    if a>=b:
        print(i)
        break

# Optimized solution
n,k=list(map(int,input().split()))
d=set(input().split())

while len(d&set(str(n)))!=0:
    n+=1
print(n)
# Original solution
N,K = list(map(int,input().split()))
D = list(map(str,list(map(int,input().split()))))

n = N
while True:
    s = str(n)
    S = set(list(s))
    for c in S:
        if c in D:
            break
    else:
        break
    n += 1
print(n)

# Optimized solution
N,K=list(map(int, input().split()))
D=set(input().split())

def check(x):
    for c in str(x):
        if c in D: return False
    return True

ans = N
while not check(ans): ans += 1
print(ans)
# Original solution
n,k = list(map(int,input().split()))
d = input().split()


f = True
while(f):
  for s in d:
    if s in str(n):
      _ = n
      n += 1
      break
  else:
    break
print(n)

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

while(True):
    x = n
    while(x):
        if x%10 in d:
            break
        x//=10
    else:
        print(n)
        quit(0)
    n += 1
# Original solution
N, K = list(map(int, input().split()))
D = {i for i in range(10)} - set(map(int, input().split()))
for i in range(N, 100000):
    if all(j in D for j in map(int, str(i))):
        print(i)
        break


# Optimized solution
N, K, *D = list(map(int, open(0).read().split()))
D = set(str(d) for d in D)
for i in range(N, 100_000):
    if set(str(i)) & D:
        continue
    print(i)
    break
# Original solution

lst_1 = input().split()

N = lst_1[0]
K = int(lst_1[1])

lst_N = list(N)

lst_hate = input().split()

flg = True

while 1:

    for i in range(len(lst_N)):

        for j in range(len(lst_hate)):

            if lst_N[i] == lst_hate[j]:
                flg = False
                break

    if flg == True:
        break

    N = ''.join(lst_N)
    N = int(N)
    N += 1
    lst_N = list(str(N))

    flg = True

N = ''.join(lst_N)
print(N)

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

k = N
"""while k > 0:
    lst.append(k % 10)
    k //= 10
#lst.reverse()"""
#print(lst)

while 1:
    flg = True
    lst = []
    N = k
    while k > 0:
        lst.append(k % 10)
        k //= 10
    lst.reverse()
    # print(lst)
    for i in range(len(lst)):
        if lst[i] in D:
            flg = False
            break
    if flg == False:
        k = N
        k += 1
    else:
        break
print(N)
# Original solution
n,k=list(map(int,input().split()))
D=set(list(map(int,input().split())))

for i in range(n,10*n):
    num=set(list(map(int,str(i))))
    if i>=n and len(D&num)==0:
        print(i)
        exit()

# Optimized solution
n,k=list(map(int,input().split()))
D=set(list(map(str,input().split())))

for i in range(n,10*n):
    num=set(list(str(i)))
    if i>=n and len(D&num)==0:
        print(i)
        exit()
# Original solution
n,k=list(map(int,input().split()))
D = list(map(str,input().split()))
x = n
while True:
  y = str(x)
  for i in range(len(y)):
    if y[i] in D:
      break
  else:
    ans = x
    break
  x += 1
print(ans)

# Optimized solution
n,k=list(map(int,input().split()))
D = list(map(str,input().split()))
x = n
while True:
  y = str(x)
  for i in y:
    if i in D:
      break
  else:
    ans = x
    break
  x += 1
print(ans)
# Original solution
# 0〜9
l=list(range(10))

# 入力
N,K=list(map(int,input().split()))
l2=list(map(int,input().split()))

ans=''
f=False

# 使用可能な数字を求める
for x in l2:
  l.remove(x)

# 集合型に変換
l=set(l)

for x in range(1,1000000):
  y=set(map(int,list(str(x))))
  if N<=x and l.issuperset(y):
    print(x)
    break

# Optimized solution
# 0〜9
l=list(range(10))

# 入力
N,K=list(map(int,input().split()))
l2=list(map(int,input().split()))

# 使用可能な数字を求める
for x in l2:
  l.remove(x)

# 集合型に変換
l=set(l)

# 1<=N<=10000 なので、答えは最大でも100000まで
for x in range(1,100001):
  # 集合型に変換
  y=set(map(int,list(str(x))))

  # Nを上回る数字かつ、使える数字のみを使用している場合
  if N<=x and l.issuperset(y):
    print(x)
    break
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())

def main():
  n,k=LI()
  
  l=LI()

  a=0
  while True:
    a+=1
    if a>=n:
      f=True
      for x in list(str(a)):
        if int(x) in l:
          f=False
          break
      if f:
        return a

print((main()))


# Optimized solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())

def main():
  n,k=LI()
  l=LS()

  ans=1
  while True:
    if ans>=n:
      s=str(ans)

      f=True
      for x in s:
        if x in l:
          f=False
          break

      if f:
        return ans

    ans+=1

print((main()))
# Original solution
amount, num = list(map(int, input().split()))

hate_num_list = list(map(str, input().split()))

while(True):

    check = 0

    for digit in str(amount):

        if digit in hate_num_list:
            check += 1

    if check == 0:
        print(amount)
        break

    else:
        amount += 1

# Optimized solution
amount, num = list(map(int, input().split()))

hated_digit = list(map(str, input().split()))

while True:
    check = 0
    for hd in hated_digit:
        if hd not in str(amount):
            check += 1

        else:
            amount += 1

    if check == num:
        print(amount)
        break
# Original solution
N, L = list(map(int, input().split()))
D = input().split()
ans = N
while 1:
    s = str(ans)
    f = 1
    for i in D:
        if i in s : f = 0
    if f : break
    ans += 1
print(ans)

# Optimized solution
def main():
    N, L = list(map(int, input().split()))
    D = input().split()
    ans = N
    while 1:
        s = str(ans)
        if not [1 for i in D if i in s] : break
        ans += 1
    print(ans)
if __name__ == '__main__':
    main()
# Original solution
import sys
readline = sys.stdin.readline

def main():
    N, K = list(map(int, readline().rstrip().split()))
    D = list(map(int, readline().rstrip().split()))
    nums = [str(i) for i in range(10)]
    for d in D:
        nums.remove(str(d))
    for i in range(N, N*10+1):
        d = str(i)
        flg = True
        for e in d:
            if e not in nums:
                flg = False
                break
        
        if flg:
            print(i)
            return


if __name__ == '__main__':
    main()

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

def main():
    N, K = list(map(int, readline().rstrip().split()))
    D = set(readline().rstrip().split())
    for i in range(N, N*10+1):
        d = str(i)
        flg = True
        for e in d:
            if e in D:
                flg = False
                break
        
        if flg:
            print(i)
            return


if __name__ == '__main__':
    main()
# Original solution
n, k = list(map(int, input().split()))
A = list(input().split())
for i in range(10 * n):
    for a in A:
        if a in str(n + i):
            break
    else:
        ans = n + i
        break
print(ans)    

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

for i in range(n * 10):
    for j in str(n + i):
        if j in A:
            break
    else:
        print((n + i))
        break
# Original solution
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N,K=list(map(int,input().split()))
    N= str(N)

    S={i for i in range(10)}
    D=set(map(int,input().split()))
    D=S-D

    def search(N):
        for i in range(len(N)):
            if int(N[i]) not in D:
                return True
            elif i==len(N)-1:
                return False

    while True:
        if search(N) ==True:
            N=str(int(N)+1)
        else:
            print(N)
            break









resolve()

# Optimized solution
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

        L={i for i in range(10)}
        U=L-D
        while True:

            sn = str(N)
            ln = len(sn)

            for i in range(ln):
                if int(sn[i]) not in U:
                    N+=1
                    break
                elif i==ln-1:
                    return int(N)
    print((main()))



resolve()
# Original solution
from collections import deque
n, m = list(map(int, input().split()))
e = [int(eval(input())) for _ in range(m)]
d = deque(i for i in range(1, n+1))
for v in e[::-1]:
    try:
        d.remove(v)
        print(v)
    except ValueError:
        pass
while d:
    print((d.popleft()))

# Optimized solution
n, m = list(map(int, input().split()))
e = [int(eval(input())) for _ in range(m)]
b = [1] * (n+1)
for v in e[::-1]:
    if b[v]:
        b[v] = 0
        print(v)
for i in range(1, n+1):
    if b[i]:
        print(i)
# Original solution
n = int(eval(input()))
G = [[] for i in range(n)]
root = 0
color_num = 0
keys = []

def get_key(n1, n2):
  if n1 > n2:
    return str(n2) + '-' + str(n1)
  return str(n1) + '-' + str(n2)

for _ in range(n - 1):
  a, b = list(map(int, input().split()))
  keys.append(get_key(a - 1, b - 1))
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
  if color_num < len(G[a - 1]):
    root = a - 1
    color_num = len(G[a - 1])
  elif color_num < len(G[b - 1]):
    root = b - 1
    color_num = len(G[b - 1])

# print(G)
# [[1], [0, 2, 3, 4], [1], [1, 6], [1, 5], [4, 7], [3], [5]]
# print(root) # 最も多い色を持つノードの番号
print(color_num)  # 必要な最小色数
queue = [root]
checked = set()
result = {}

min_colors = [set(range(color_num)) for i in range(n)]

while len(queue) > 0:
  node = queue.pop(0)
  # print(node + 1)
  # ks = list(range(color_num))
  # print(node)
  # print(ks)
  # for node2 in G[node]:
  #   key = get_key(node, node2)
  #   if key in result:
  #     ks.pop(result[key])
  for node2 in G[node]:
    if node2 not in checked:
      key = get_key(node, node2)
      # result[key] = ks.pop(0)
      result[key] = min_colors[node].pop()
      min_colors[node2].discard(result[key])
      queue.append(node2)
  checked.add(node)

for k in keys:
  print((result[k] + 1))


# Optimized solution
n = int(eval(input()))
G = [[] for i in range(n)]
root = 0
color_num = 0

for i in range(n - 1):
  a, b = list(map(int, input().split()))
  G[a - 1].append((b - 1, i))
  G[b - 1].append((a - 1, i))
  if color_num < len(G[a - 1]):
    root = a - 1
    color_num = len(G[a - 1])
  elif color_num < len(G[b - 1]):
    root = b - 1
    color_num = len(G[b - 1])

# print(G)
# [[1], [0, 2, 3, 4], [1], [1, 6], [1, 5], [4, 7], [3], [5]]
# print(root) # 最も多い色を持つノードの番号
print(color_num)  # 必要な最小色数
queue = [(root, -1)]
checked = set()
answer = [-1] * (n - 1)

while len(queue) > 0:
  node, c = queue.pop(0)
  color = 1
  for node2, index in G[node]:
    if node2 not in checked:
      if color == c:
        color = c + 1
      answer[index] = color
      color += 1
      queue.append((node2, answer[index]))
  checked.add(node)
print(('\n'.join(map(str, answer))))
# Original solution
N = int(eval(input()))
ABs = []
for i in range(N - 1):
    ABs.append(tuple(map(int, input().split())))

Cs = [0] * (N + 1)
for i in range(N - 1):
    Cs[ABs[i][0]] += 1
    Cs[ABs[i][1]] += 1
K = max(Cs)
print(K)

ABsc = [[False] * (K + 1) for _ in range(N + 1)]
Tr = [[] for _ in range(N + 1)]
for i in range(N - 1):
    p = min(ABs[i][0], ABs[i][1])
    c = max(ABs[i][0], ABs[i][1])
    Tr[p].append((c, i))
import collections

d = collections.deque()
d.append(1)


def minC(i):
    for j in range(1, K + 1):
        if not ABsc[i][j]:
            return j


Cis = [1] * N
while (len(d) > 0):
    p = d.popleft()
    for (c, i) in Tr[p]:
        d.append(c)
        col = minC(p)
        ABsc[p][col] = True
        ABsc[c][col] = True
        Cis[i] = col

for i in range(N - 1):
    print((Cis[i]))

# Optimized solution
N = int(eval(input()))
ABs = []
for i in range(N - 1):
    ABs.append(tuple(map(int, input().split())))

Cs = [0] * (N + 1)
Tr = [[] for _ in range(N + 1)]
for i in range(N - 1):
    Cs[ABs[i][0]] += 1
    Cs[ABs[i][1]] += 1
    p = min(ABs[i][0], ABs[i][1])
    c = max(ABs[i][0], ABs[i][1])
    Tr[p].append((c, i))
K = max(Cs)
print(K)

import collections

d = collections.deque()
d.append(1)

Pc = [0] * (N + 1)
Nc = [1] * (N + 1)
ABsc = [0] * (N + 1)
Cis = [1] * N
while (len(d) > 0):
    p = d.popleft()
    for (c, i) in Tr[p]:
        d.append(c)
        col = Nc[p]
        if Pc[p] == col:
            col += 1
        Nc[p] = col + 1
        Pc[c] = col
        Cis[i] = col

for i in range(N - 1):
    print((Cis[i]))
# Original solution
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)

N = int(eval(input()))
count = [[] for _ in range(N)]
inputs = []

for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    count[a - 1].append(b - 1)
    count[b - 1].append(a - 1)
    inputs.append(sorted([a - 1, b - 1]))

K = 0
for c in count:
    K = max(K, len(c))
print(K)

def dfs(root, count):
    done = [-1 for _ in range(N)]
    done[root] = 0
    info = []
    d = deque([root])
    r = d.pop()
    childs = count[r]
    tmp = 1
    for c in childs:
        if done[c] == -1:
            d.append([c, r, tmp])
            tmp += 1
            done[c] += 1
    while d:
        data = d.pop()
        info.append(data)
        childs = count[data[0]]
        tmp = 1
        for c in childs:
            if done[c] == -1:
                if tmp != data[2]:
                    d.append([c, data[0], tmp])
                else:
                    tmp += 1
                    d.append([c, data[0], tmp])
                tmp += 1
                done[c] += 1
    return info

info = dfs(0, count)
info_new = [[sorted([i[0], i[1]]), i[2]] for i in info]

for i in inputs:
    for k in info_new:
        if i == k[0]:
            print((k[1]))

# Optimized solution
import sys
from collections import deque, OrderedDict
sys.setrecursionlimit(10 ** 7)

N = int(eval(input()))
count = [[] for _ in range(N)]
inputs = OrderedDict()

for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    count[a - 1].append(b - 1)
    count[b - 1].append(a - 1)
    inputs["-".join(list(map(str, sorted([a - 1, b - 1]))))] = 0

K = 0
for c in count:
    K = max(K, len(c))
print(K)

def dfs(root, count, inputs):
    done = [-1 for _ in range(N)]
    done[root] = 0
    d = deque([root])
    r = d.pop()
    childs = count[r]
    tmp = 1
    for c in childs:
        if done[c] == -1:
            d.append([c, r, tmp])
            tmp += 1
            done[c] += 1
    while d:
        data = d.pop()
        inputs["-".join(list(map(str, sorted(data[:2]))))] = data[2]
        childs = count[data[0]]
        tmp = 1
        for c in childs:
            if done[c] == -1:
                if tmp != data[2]:
                    d.append([c, data[0], tmp])
                else:
                    tmp += 1
                    d.append([c, data[0], tmp])
                tmp += 1
                done[c] += 1
    
    return inputs

inputs = dfs(0, count, inputs)

for i in list(inputs.values()):
    print(i)
# Original solution
import sys
input = sys.stdin.readline


n = int(eval(input()))

GRAPH = {i:[] for i in range(1, n + 1)}
EDGES = []
COLORS = {(0, 1):0}
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    GRAPH[a].append(b)
    GRAPH[b].append(a)
    EDGES.append((a, b))
    COLORS[(a, b)] = 0

PREV = {1:0}
Q = [1]
while Q:
    now = Q.pop(0)
    for vertex in GRAPH[now]:
        if vertex == PREV[now]:
            continue
        next = vertex
        PREV[next] = now
        Q.append(next)

Q = [1]
while Q:
    now = Q.pop(0)
    prev = PREV[now]
    a, b = min(now, prev), max(now, prev)
    used = COLORS[(a, b)]
    
    color = 1
    for vertex in GRAPH[now]:
        if vertex == prev:
            continue
        next = vertex
        a, b = min(now, next), max(now, next)
        if color == used:
            color += 1
            COLORS[(a, b)] = color
            color += 1
        else:
            COLORS[(a, b)] = color
            color += 1
        Q.append(next)

print((max(COLORS.values())))
for edge in EDGES:
    print((COLORS[edge]))


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


n = int(eval(input()))

GRAPH = {i:[] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    GRAPH[a].append(b)
    GRAPH[b].append(a)
    EDGES.append((a, b))

PREV = {1:0}
Q = [1]
while Q:
    now = Q.pop(0)
    for vertex in GRAPH[now]:
        if vertex == PREV[now]:
            continue
        next = vertex
        PREV[next] = now
        Q.append(next)

COLORS = {(0, 1):0}
Q = [1]
while Q:
    now = Q.pop(0)
    prev = PREV[now]
    a, b = min(now, prev), max(now, prev)
    used = COLORS[(a, b)]
    
    color = 1
    for vertex in GRAPH[now]:
        if vertex == prev:
            continue
        next = vertex
        a, b = min(now, next), max(now, next)
        if color == used:
            color += 1
            COLORS[(a, b)] = color
            color += 1
        else:
            COLORS[(a, b)] = color
            color += 1
        Q.append(next)

print((max(COLORS.values())))
for edge in EDGES:
    print((COLORS[edge]))