# -*- coding: utf-8 -*-

import sys,math,itertools

input = sys.stdin.readline

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

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

d_set = set(d)

d_all = set(range(10))

d_use = [str(a) for a in list(d_all - d_set)]

keta = int(math.log10(n))+1

l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))]

l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))]



print((min(min(l1), min(l2))))
# -*- coding: utf-8 -*-

import sys,math,itertools

input = sys.stdin.readline

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

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

d_set = set(d)

d_all = set(range(10))

d_use = [str(a) for a in list(d_all - d_set)]

keta = int(math.log10(n))+1

# l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))]

# l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))]

temp = 100000

for i in list(itertools.product(d_use, repeat=keta+1)):

  a = int(''.join(list(i)))

  if (a>=n)&(a<temp):

    temp = a

for i in list(itertools.product(d_use, repeat=keta)):

  a = int(''.join(list(i)))

  if (a>=n)&(a<temp):

    temp = a



print(temp)
# -*- coding: utf-8 -*-
import sys, math, itertools

input = sys.stdin.readline
n, k = list(map(int, input().split()))
d = [int(_) for _ in input().split()]
d_set = set(d)
d_all = set(range(10))
d_use = [str(a) for a in list(d_all - d_set)]
keta = int(math.log10(n)) + 1
l1 = [
    int("".join(list(a))) if int("".join(list(a))) >= n else 100000
    for a in list(itertools.product(d_use, repeat=keta + 1))
]
l2 = [
    int("".join(list(a))) if int("".join(list(a))) >= n else 100000
    for a in list(itertools.product(d_use, repeat=keta))
]
print((min(min(l1), min(l2))))

# -*- coding: utf-8 -*-
import sys, math, itertools

input = sys.stdin.readline
n, k = list(map(int, input().split()))
d = [int(_) for _ in input().split()]
d_set = set(d)
d_all = set(range(10))
d_use = [str(a) for a in list(d_all - d_set)]
keta = int(math.log10(n)) + 1
# l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))]
# l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))]
temp = 100000
for i in list(itertools.product(d_use, repeat=keta + 1)):
    a = int("".join(list(i)))
    if (a >= n) & (a < temp):
        temp = a
for i in list(itertools.product(d_use, repeat=keta)):
    a = int("".join(list(i)))
    if (a >= n) & (a < temp):
        temp = a
print(temp)

-l1 = [ -    int("".join(list(a))) if int("".join(list(a))) >= n else 100000 -    for a in list(itertools.product(d_use, repeat=keta + 1)) -] -l2 = [ -    int("".join(list(a))) if int("".join(list(a))) >= n else 100000 -    for a in list(itertools.product(d_use, repeat=keta)) -] -print((min(min(l1), min(l2)))) +# l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))] +# l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))] +temp = 100000 +for i in list(itertools.product(d_use, repeat=keta + 1)): +    a = int("".join(list(i))) +    if (a >= n) & (a < temp): +        temp = a +for i in list(itertools.product(d_use, repeat=keta)): +    a = int("".join(list(i))) +    if (a >= n) & (a < temp): +        temp = a +print(temp)