@staticmethod
def c():
    (n, k, *d) = sys.stdin.read().split()
    l = len(n)
    ok = sorted((set(string.digits) - set(d)))
    cand = ([int(''.join(p)) for p in itertools.product(ok, repeat=l)] + [int((min((x for x in ok if (x > '0'))) + (min(ok) * l)))])
    print(cand[bi_l(cand, int(n))])
@staticmethod
def c():
    (n, k, *d) = sys.stdin.read().split()
    l = len(n)
    ok = sorted((set(string.digits) - set(d)))
    cand = ([int(.join(p)) for p in itertools.product(ok, repeat=l)] + [int((min((x for x in ok if (x > '0'))) + (min(ok) * l)))])
    print(cand[bi_l(cand, int(n))])