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

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



use = [i for i in range(10)]



for _d in d:

    use.remove(_d)





while True:

    ok = True

    s = str(n)

    for i in range(len(s)):

        if int(s[i]) not in use:

            ok = False

            break



    if ok:

        print(n)

        exit()

    else:

        n += 1



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

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

money = n

ok = True

while True:

    for d in D:

        if d in str(money):

            ok = False

            break

    if ok:

        print(money)

        break

    money += 1

    ok = True
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
use = [i for i in range(10)]
for _d in d:
    use.remove(_d)
while True:
    ok = True
    s = str(n)
    for i in range(len(s)):
        if int(s[i]) not in use:
            ok = False
            break
    if ok:
        print(n)
        exit()
    else:
        n += 1

n, k = list(map(int, input().split()))
D = list(map(str, input().split()))
money = n
ok = True
while True:
    for d in D:
        if d in str(money):
            ok = False
            break
    if ok:
        print(money)
        break
    money += 1
    ok = True

-d = list(map(int, input().split())) -use = [i for i in range(10)] -for _d in d: -    use.remove(_d) +D = list(map(str, input().split())) +money = n +ok = True -    ok = True -    s = str(n) -    for i in range(len(s)): -        if int(s[i]) not in use: +    for d in D: +        if d in str(money): -        print(n) -        exit() -    else: -        n += 1 +        print(money) +        break +    money += 1 +    ok = True