import sys



n, k, *dislikes = sys.stdin.read().split()

n = int(n)

dislikes = set(dislikes)



def main():

    i = n

    while True:

        if set(str(i)) & dislikes:

            i += 1

            continue

        return i



if __name__ == '__main__':

    ans = main()

    print(ans)
import sys

from string import digits



n, k, *d = sys.stdin.read().split()

d = set(digits) - set(d)

l = len(n)



def main(d):

    res = ''

    flag = True

    for i in range(l):

        if flag:

            if n[i] in d:

                res += n[i]

            else:

                flag = False

                for j in range(int(n[i]), 10):

                    if str(j) in d:

                        res += str(j)

                        break

                else:

                    break

        else:

            res += min(d)

    else:

        print(res)

        return

    d = sorted(d)

    res = d[0] * (l + 1) if d[0] != '0' else d[1] + '0' * l

    print(res)



if __name__ ==  '__main__':

    main(d)
import sys

n, k, *dislikes = sys.stdin.read().split()
n = int(n)
dislikes = set(dislikes)


def main():
    i = n
    while True:
        if set(str(i)) & dislikes:
            i += 1
            continue
        return i


if __name__ == "__main__":
    ans = main()
    print(ans)

import sys
from string import digits

n, k, *d = sys.stdin.read().split()
d = set(digits) - set(d)
l = len(n)


def main(d):
    res = ""
    flag = True
    for i in range(l):
        if flag:
            if n[i] in d:
                res += n[i]
            else:
                flag = False
                for j in range(int(n[i]), 10):
                    if str(j) in d:
                        res += str(j)
                        break
                else:
                    break
        else:
            res += min(d)
    else:
        print(res)
        return
    d = sorted(d)
    res = d[0] * (l + 1) if d[0] != "0" else d[1] + "0" * l
    print(res)


if __name__ == "__main__":
    main(d)

+from string import digits -n, k, *dislikes = sys.stdin.read().split() -n = int(n) -dislikes = set(dislikes) +n, k, *d = sys.stdin.read().split() +d = set(digits) - set(d) +l = len(n) -def main(): -    i = n -    while True: -        if set(str(i)) & dislikes: -            i += 1 -            continue -        return i +def main(d): +    res = "" +    flag = True +    for i in range(l): +        if flag: +            if n[i] in d: +                res += n[i] +            else: +                flag = False +                for j in range(int(n[i]), 10): +                    if str(j) in d: +                        res += str(j) +                        break +                else: +                    break +        else: +            res += min(d) +    else: +        print(res) +        return +    d = sorted(d) +    res = d[0] * (l + 1) if d[0] != "0" else d[1] + "0" * l +    print(res) -    ans = main() -    print(ans) +    main(d)