import itertools



N, K = list(map(int, input().split())) # N円の品物、K個の嫌いな数字

D = set(list(map(int, input().split()))) # 嫌いな数字のリスト

base = set(range(10))



target_num = base - D

keta = len(str(N))



answer = float('inf')

for p in itertools.product(target_num, repeat=keta):

    temp = 0

    for i, num in enumerate(p):

        temp += num * 10**i

        

    if temp >= N:

        answer = min(answer, temp)



for p in itertools.product(target_num, repeat=keta+1):

    temp = 0

    for i, num in enumerate(p):

        temp += num * 10**i

        

    if temp >= N:

        answer = min(answer, temp)



print(answer)
import itertools



def cal(N, target_num, keta):

    answer = float('inf')

    for p in itertools.product(target_num, repeat=keta):

        temp = 0

        for i, num in enumerate(p):

            temp += num * 10**i

            

        if temp >= N:

            answer = min(answer, temp)



    return answer



if __name__ == "__main__":

    N, K = list(map(int, input().split())) # N円の品物、K個の嫌いな数字

    D = set(list(map(int, input().split()))) # 嫌いな数字のリスト

    base = set(range(10))



    target_num = base - D

    keta = len(str(N))



    answer = min(cal(N, target_num, keta), cal(N, target_num, keta+1))



    print(answer)
import itertools

N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字
D = set(list(map(int, input().split())))  # 嫌いな数字のリスト
base = set(range(10))
target_num = base - D
keta = len(str(N))
answer = float("inf")
for p in itertools.product(target_num, repeat=keta):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
    if temp >= N:
        answer = min(answer, temp)
for p in itertools.product(target_num, repeat=keta + 1):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
    if temp >= N:
        answer = min(answer, temp)
print(answer)

import itertools


def cal(N, target_num, keta):
    answer = float("inf")
    for p in itertools.product(target_num, repeat=keta):
        temp = 0
        for i, num in enumerate(p):
            temp += num * 10**i
        if temp >= N:
            answer = min(answer, temp)
    return answer


if __name__ == "__main__":
    N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字
    D = set(list(map(int, input().split())))  # 嫌いな数字のリスト
    base = set(range(10))
    target_num = base - D
    keta = len(str(N))
    answer = min(cal(N, target_num, keta), cal(N, target_num, keta + 1))
    print(answer)

-N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字 -D = set(list(map(int, input().split())))  # 嫌いな数字のリスト -base = set(range(10)) -target_num = base - D -keta = len(str(N)) -answer = float("inf") -for p in itertools.product(target_num, repeat=keta): -    temp = 0 -    for i, num in enumerate(p): -        temp += num * 10**i -    if temp >= N: -        answer = min(answer, temp) -for p in itertools.product(target_num, repeat=keta + 1): -    temp = 0 -    for i, num in enumerate(p): -        temp += num * 10**i -    if temp >= N: -        answer = min(answer, temp) -print(answer) + +def cal(N, target_num, keta): +    answer = float("inf") +    for p in itertools.product(target_num, repeat=keta): +        temp = 0 +        for i, num in enumerate(p): +            temp += num * 10**i +        if temp >= N: +            answer = min(answer, temp) +    return answer + + +if __name__ == "__main__": +    N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字 +    D = set(list(map(int, input().split())))  # 嫌いな数字のリスト +    base = set(range(10)) +    target_num = base - D +    keta = len(str(N)) +    answer = min(cal(N, target_num, keta), cal(N, target_num, keta + 1)) +    print(answer)