import itertools

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

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

ls = []

for i in range(10):

    if i not in d:

        ls.append(i)

mp = 10 ** 9

for j in range(len(str(n)), 7):

    for i in itertools.product(ls, repeat=j):

        m = int("".join(map(str, i)))

        if m >= n:

            mp = min(mp, m)

print(mp)

def slove():

    import sys

    import collections

    input = sys.stdin.readline

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

    d = collections.defaultdict(int)

    for i in list(map(int, input().rstrip('\n').split())):

        d[i]

    for i in range(n, 10 ** 10):

        s = str(i)

        b = True

        for j in range(len(s)):

            if int(s[j]) in d:

                b = False

                break

        if b:

            print(i)

            exit()





if __name__ == '__main__':

    slove()

import itertools

n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
ls = []
for i in range(10):
    if i not in d:
        ls.append(i)
mp = 10**9
for j in range(len(str(n)), 7):
    for i in itertools.product(ls, repeat=j):
        m = int("".join(map(str, i)))
        if m >= n:
            mp = min(mp, m)
print(mp)

def slove():
    import sys
    import collections

    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip("\n").split()))
    d = collections.defaultdict(int)
    for i in list(map(int, input().rstrip("\n").split())):
        d[i]
    for i in range(n, 10**10):
        s = str(i)
        b = True
        for j in range(len(s)):
            if int(s[j]) in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == "__main__":
    slove()

-import itertools +def slove(): +    import sys +    import collections -n, k = list(map(int, input().split())) -d = list(map(int, input().split())) -ls = [] -for i in range(10): -    if i not in d: -        ls.append(i) -mp = 10**9 -for j in range(len(str(n)), 7): -    for i in itertools.product(ls, repeat=j): -        m = int("".join(map(str, i))) -        if m >= n: -            mp = min(mp, m) -print(mp) +    input = sys.stdin.readline +    n, k = list(map(int, input().rstrip("\n").split())) +    d = collections.defaultdict(int) +    for i in list(map(int, input().rstrip("\n").split())): +        d[i] +    for i in range(n, 10**10): +        s = str(i) +        b = True +        for j in range(len(s)): +            if int(s[j]) in d: +                b = False +                break +        if b: +            print(i) +            exit() + + +if __name__ == "__main__": +    slove()