from functools import reduce

import operator as op



n = int(input().split(' ')[0])

ds_str = input().split(' ')

ds = list(map(int, ds_str))



for m in range(n, 100000):

    mlist = list(map(int, list(str(m))))

    if reduce(op.or_, [x in ds for x in mlist]):

        continue

    else:

        print(m)

        break

from functools import reduce

import operator as op



n = int(input().split(' ')[0])

ds_str = input().split(' ')

ds = set(map(int, ds_str))



for m in range(n, 100000):

    mlist = list(map(int, list(str(m))))

    if reduce(op.or_, [x in ds for x in mlist]):

        continue

    else:

        print(m)

        break

from functools import reduce
import operator as op

n = int(input().split(" ")[0])
ds_str = input().split(" ")
ds = list(map(int, ds_str))
for m in range(n, 100000):
    mlist = list(map(int, list(str(m))))
    if reduce(op.or_, [x in ds for x in mlist]):
        continue
    else:
        print(m)
        break

from functools import reduce
import operator as op

n = int(input().split(" ")[0])
ds_str = input().split(" ")
ds = set(map(int, ds_str))
for m in range(n, 100000):
    mlist = list(map(int, list(str(m))))
    if reduce(op.or_, [x in ds for x in mlist]):
        continue
    else:
        print(m)
        break

-ds = list(map(int, ds_str)) +ds = set(map(int, ds_str))