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

d = list(input().split())



from itertools import count



for i in count(n):

    s = str(i)

    for bit in s:

        if bit in d:

            break

    else:

        print(i)

        break



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

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

def v(n):

    for c in map(int, str(n)):

        if (c in d):

            return False

    return True

while (v(n) == False):

    n += 1

print(n)
n, k = list(map(int, input().split()))
d = list(input().split())
from itertools import count

for i in count(n):
    s = str(i)
    for bit in s:
        if bit in d:
            break
    else:
        print(i)
        break

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


def v(n):
    for c in map(int, str(n)):
        if c in d:
            return False
    return True


while v(n) == False:
    n += 1
print(n)

-d = list(input().split()) -from itertools import count +d = list(map(int, input().split())) -for i in count(n): -    s = str(i) -    for bit in s: -        if bit in d: -            break -    else: -        print(i) -        break + +def v(n): +    for c in map(int, str(n)): +        if c in d: +            return False +    return True + + +while v(n) == False: +    n += 1 +print(n)