Iroha dislikes certain digits and wants to pay the minimum amount of money at a cashier without using those digits. Given the total amount she needs to pay and the disliked digits, find the minimum amount she can hand to the cashier. The input consists of the total amount and the disliked digits. Output the minimum amount she will hand to the cashier. Constraints: 1 ≤ N < 10000, 1 ≤ K < 10, 0 ≤ D1 < D2 < … < DK ≤ 9, {D1,D2,...,DK} ≠ {1,2,3,4,5,6,7,8,9}. Example: Input: 1000 8, 1 3 4 5 6 7 8 9, Output: 2000.

# Buggy version:
n, k = map(int, input().split())
d = list(map(int, input().split()))

def is_ok(num):
  s = str(num)
  for ng in d:
    if ng in s: return False
  
  return True

while True:
  if is_ok(n):
    print(n)
    exit()
  
  n += 1
  

# Fixed version:
n, k = map(int, input().split())
d = input().split()

def is_ok(num):
  s = str(num)
  for ng in d:
    if ng in s: return False
  
  return True

while True:
  if is_ok(n):
    print(n)
    exit()
  
  n += 1

# Buggy version:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)
def FindFirstBig(okLines,m,FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig

for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines,m,FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag,len(newMoney),1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        newMoney.insert(0,okLines[0])
        for i in range(ProblemFlag, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

# Fixed version:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)


def FindFirstBig(okLines, m, FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig


for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines, m, FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0 and ProblemFlag is not -1:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag, len(newMoney), 1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        if okLines[0] != '0':
            newMoney.insert(0, okLines[0])
        else:
            newMoney.insert(0, okLines[1])
        for i in range(ProblemFlag + 1, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

# Buggy version:
n, k = map(int, input().split())
d = map(str, input().split())
digits = set(d)
num = {str(i) for i in range(0,10)}
left = num - digits
for i in range(N, 100000):
    Num = set(str(i))
    if Num <= left:
        print(i)
        break

# Fixed version:
n, k = map(int, input().split())
d = map(str, input().split())
digits = set(d)
num = {str(i) for i in range(0,10)}
left = num - digits
for i in range(n, 100000):
    Nums = set(str(i))
    if Nums <= left:
        print(i)
        break

# Buggy version:
n, k = map(int, input().split())
a = list(input().split())
for i in range(n+1, 10**6):
  if all([j not in a for j in str(i)]):
 #   print([j for j in str(i)])
    print(i)
    exit()

# Fixed version:
n, k = map(int, input().split())
a = list(input().split())
for i in range(n, 10**6):
  if all([j not in a for j in str(i)]):
 #   print([j for j in str(i)])
    print(i)
    exit()

# Buggy version:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums < available:
        print(i)
        break

# Fixed version:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

# Buggy version:
n,k,*a=map(int,open(0).read().split())
while any(s in set(a)for s in str(n)):n+=1
print(n)

# Fixed version:
n,k,*a=open(0).read().split();n=int(n)
while any(s in set(a)for s in str(n)):n+=1
print(n)

# Buggy version:
n,k=map(int,input().split())
x = list(map(int,input().split()))
t = 1
s = n
while t:
    for i in range(k):
        if str(x[i]) in str(n+s):
            break
        t = 0
    s+=1
print(n+s-1)

# Fixed version:
n,k=map(int,input().split())
x = list(map(int,input().split()))
t = 1
s = n
f=0
while t:
    for i in range(k):
        f = 0
        if str(x[i]) in str(s):
            break
        elif i == k -1:t = 0
    s+=1
print(s-1)

# Buggy version:
ar = list(map(int,input().split(" ")))
while True:
    count = 0
    br = list(str(a))
    for r in br:
        if int(r) in ar:
            count += 1
    if count == 0:
        print(a)
        break
    else:
        a += 1

# Fixed version:
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
while True:
    count = 0
    br = list(str(a))
    for r in br:
        if int(r) in ar:
            count += 1
    if count == 0:
        print(a)
        break
    else:
        a += 1

# Buggy version:
import math

def ceil(n, i):
    dec = 10 ** i
    return n // dec * dec
def floor(n, i):
    dec = 10 ** i
    return n // dec * dec + dec

(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
l = []

for i in range(0, 10):
    if i not in d:
        l.append(i)
for i in range(1, len(str(n)) + 1):
    nown = n // (10 ** (i - 1)) % 10
    ok = False
    print(nown)
    for j in l:
        if j == nown:
            ok = True
            break
        elif j > nown:
            ok = True
            n = ceil(n, i)
            print(str(j) + str(l[0]) * (i - 1))
            n += int(str(j) + str(l[0]) * (i - 1))
            break
    if not (ok):
        n = floor(n, i)
        n += int(str(l[0]) * i)
        
print(n)




# Fixed version:
def ceil(n, i):
    dec = 10 ** i
    return n // dec * dec

(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
l = []
for i in range(0, 10):
    if i not in d:
        l.append(i)
i = 1
while len(str(n)) >= i:
    nown = n // (10 ** (i - 1)) % 10
    ok = False
    for j in l:
        if j == nown:
            ok = True
            break
        elif j > nown:
            ok = True
            n = ceil(n, i)
            n += int(str(j) + str(l[0]) * (i - 1))
            break
    if not (ok):
        n = ceil(n, i) + 10 ** i
        n += int(str(l[0]) * i)
    i += 1
print(n)

# Buggy version:
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


N,K = input.split()
N = int(N)

d = [int(i) for i in input.split()]

for i in range(10001):
    if i > N :
        if dig_check(i,d):
            print(i)
            break


# Fixed version:
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


N,K = input().split()
N = int(N)

d = [int(i) for i in input().split()]

for i in range(100001):
    if i >= N :
        if dig_check(i,d):
            print(i)
            break

# Buggy version:
n,k=map(int,input().split())
dislike=list(map(int,input().split()))
print(dislike)

while 1:
    for i in range(len(str(n))):
        if int(str(n)[i]) in dislike:
            break
        print(n)
        exit()
    n+=1

# Fixed version:
n,k=map(int,input().split())
dislike=list(map(int,input().split()))


while 1:
    for i in range(len(str(n))):
        if int(str(n)[i]) in dislike:
            break
        if i==len(str(n))-1:
            print(n)
            exit()
    n+=1

# Buggy version:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    for ii in range(n, 10**9):
        l = [int(x) for x in list(str(ii))]
        ll =[q for q in l if q in d]
        print(ii, ll)
        if len(ll) == 0:
            print(ii)
            break
if __name__ == "__main__":
    main()

# Fixed version:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    for ii in range(n, 10**9):
        l = [int(x) for x in list(str(ii))]
        ll =[q for q in l if q in d]
        if len(ll) == 0:
            print(ii)
            break
if __name__ == "__main__":
    main()