import sys



import numpy as np

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random

from collections import deque, defaultdict, Counter

from heapq import heappush, heappop

from itertools import permutations, combinations, product, accumulate, groupby

from bisect import bisect_left, bisect_right, insort_left, insort_right

from operator import itemgetter as ig

sys.setrecursionlimit(10 ** 7)

inf = 10 ** 20

INF = float("INF")

mod = 10 ** 9 + 7

"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];

ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];

ddn9 = ddn + [(0, 0)]

for dx, dy in dd:

        nx = j + dx; ny = i + dy

            if 0 <= nx < w and 0 <= ny < h:"""



def wi(): return list(map(int, sys.stdin.readline().split()))

def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint

def ws(): return sys.stdin.readline().split()

def si(): return int(sys.stdin.readline())  # SingleInt

def ss(): return eval(input())

def hi(n): return [si() for _ in range(n)]

def hs(n): return [ss() for _ in range(n)]  # HeightString

def s_list(): return list(eval(input()))

def mi(n): return [wi() for _ in range(n)]  # MatrixInt

def mip(n): return [wip() for _ in range(n)]

def ms(n): return [ws() for _ in range(n)]

def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid

def grid(n): return [s_list() for _ in range(n)]





def main():



    n, k = input().split()

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

    use = []

    for i in range(0,10):

        if i in d:

            continue

        else:

            use.append(i)



    flag = False

    for i in range(int(n),10*int(n)+1):

        number = str(i)

        for j in range(len(number)):

            if j != len(number)-1:

                if number[j] not in str(use):

                    break

            else:

                if number[j] in str(use):

                    flag = True

                else:

                    break



        if flag:

            print(i)

            break





if __name__ == '__main__':

    main()
import sys



import numpy as np

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random

from collections import deque, defaultdict, Counter

from heapq import heappush, heappop

from itertools import permutations, combinations, product, accumulate, groupby

from bisect import bisect_left, bisect_right, insort_left, insort_right

from operator import itemgetter as ig

sys.setrecursionlimit(10 ** 7)

inf = 10 ** 20

INF = float("INF")

mod = 10 ** 9 + 7

"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];

ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];

ddn9 = ddn + [(0, 0)]

for dx, dy in dd:

        nx = j + dx; ny = i + dy

            if 0 <= nx < w and 0 <= ny < h:"""



def wi(): return list(map(int, sys.stdin.readline().split()))

def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint

def ws(): return sys.stdin.readline().split()

def si(): return int(sys.stdin.readline())  # SingleInt

def ss(): return eval(input())

def hi(n): return [si() for _ in range(n)]

def hs(n): return [ss() for _ in range(n)]  # HeightString

def s_list(): return list(eval(input()))

def mi(n): return [wi() for _ in range(n)]  # MatrixInt

def mip(n): return [wip() for _ in range(n)]

def ms(n): return [ws() for _ in range(n)]

def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid

def grid(n): return [s_list() for _ in range(n)]





def main():



    n,m = list(map(str, input().split()))

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

    use = []

    for i in range(0,10):

        if i not in d:

           use.append(str(i))

    #print(use)

    ans_list = []

    for start in use:

        stack = deque()

        stack.append(start)

        ans = ''

        while stack:

            x = stack.pop()

            if int(n) <= int(x):

                ans_list.append(int(x))

            else:

                for tumu in use:

                    if len(x + tumu) <= len(n) + 1:

                        stack.append(x + tumu)



    print((min(ans_list)))



if __name__ == '__main__':

    main()

import sys
import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig

sys.setrecursionlimit(10**7)
inf = 10**20
INF = float("INF")
mod = 10**9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""


def wi():
    return list(map(int, sys.stdin.readline().split()))


def wip():
    return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint


def ws():
    return sys.stdin.readline().split()


def si():
    return int(sys.stdin.readline())  # SingleInt


def ss():
    return eval(input())


def hi(n):
    return [si() for _ in range(n)]


def hs(n):
    return [ss() for _ in range(n)]  # HeightString


def s_list():
    return list(eval(input()))


def mi(n):
    return [wi() for _ in range(n)]  # MatrixInt


def mip(n):
    return [wip() for _ in range(n)]


def ms(n):
    return [ws() for _ in range(n)]


def num_grid(n):
    return [
        [int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)
    ]  # NumberGrid


def grid(n):
    return [s_list() for _ in range(n)]


def main():
    n, k = input().split()
    d = list(map(int, input().split()))
    use = []
    for i in range(0, 10):
        if i in d:
            continue
        else:
            use.append(i)
    flag = False
    for i in range(int(n), 10 * int(n) + 1):
        number = str(i)
        for j in range(len(number)):
            if j != len(number) - 1:
                if number[j] not in str(use):
                    break
            else:
                if number[j] in str(use):
                    flag = True
                else:
                    break
        if flag:
            print(i)
            break


if __name__ == "__main__":
    main()

import sys
import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig

sys.setrecursionlimit(10**7)
inf = 10**20
INF = float("INF")
mod = 10**9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""


def wi():
    return list(map(int, sys.stdin.readline().split()))


def wip():
    return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint


def ws():
    return sys.stdin.readline().split()


def si():
    return int(sys.stdin.readline())  # SingleInt


def ss():
    return eval(input())


def hi(n):
    return [si() for _ in range(n)]


def hs(n):
    return [ss() for _ in range(n)]  # HeightString


def s_list():
    return list(eval(input()))


def mi(n):
    return [wi() for _ in range(n)]  # MatrixInt


def mip(n):
    return [wip() for _ in range(n)]


def ms(n):
    return [ws() for _ in range(n)]


def num_grid(n):
    return [
        [int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)
    ]  # NumberGrid


def grid(n):
    return [s_list() for _ in range(n)]


def main():
    n, m = list(map(str, input().split()))
    d = list(map(int, input().split()))
    use = []
    for i in range(0, 10):
        if i not in d:
            use.append(str(i))
    # print(use)
    ans_list = []
    for start in use:
        stack = deque()
        stack.append(start)
        ans = ""
        while stack:
            x = stack.pop()
            if int(n) <= int(x):
                ans_list.append(int(x))
            else:
                for tumu in use:
                    if len(x + tumu) <= len(n) + 1:
                        stack.append(x + tumu)
    print((min(ans_list)))


if __name__ == "__main__":
    main()

-    n, k = input().split() +    n, m = list(map(str, input().split())) -        if i in d: -            continue -        else: -            use.append(i) -    flag = False -    for i in range(int(n), 10 * int(n) + 1): -        number = str(i) -        for j in range(len(number)): -            if j != len(number) - 1: -                if number[j] not in str(use): -                    break +        if i not in d: +            use.append(str(i)) +    # print(use) +    ans_list = [] +    for start in use: +        stack = deque() +        stack.append(start) +        ans = "" +        while stack: +            x = stack.pop() +            if int(n) <= int(x): +                ans_list.append(int(x)) -                if number[j] in str(use): -                    flag = True -                else: -                    break -        if flag: -            print(i) -            break +                for tumu in use: +                    if len(x + tumu) <= len(n) + 1: +                        stack.append(x + tumu) +    print((min(ans_list)))