import sys

import numpy as np

read = sys.stdin.readline





def main(n, k, a):

    for i in np.arange(n, 100000):

        ok = True

        j = i

        while j:

            ok &= j % 10 not in a

            j //= 10

        if ok:

            print(i)

            break





if __name__ == '__main__':

    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')

    a = np.fromstring(read(), dtype=np.int32, sep=' ')

    main(n, k, a)

import sys

import numpy as np

read = sys.stdin.readline





def main(n, k, a):

    for i in np.arange(n, 100000):

        ok = True

        for j in str(i):

            ok &= j not in a

        if ok:

            print(i)

            break





if __name__ == '__main__':

    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')

    a = set(read().split())

    main(n, k, a)

import sys
import numpy as np

read = sys.stdin.readline


def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = True
        j = i
        while j:
            ok &= j % 10 not in a
            j //= 10
        if ok:
            print(i)
            break


if __name__ == "__main__":
    n, k = np.fromstring(read(), dtype=np.int32, sep=" ")
    a = np.fromstring(read(), dtype=np.int32, sep=" ")
    main(n, k, a)

import sys
import numpy as np

read = sys.stdin.readline


def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = True
        for j in str(i):
            ok &= j not in a
        if ok:
            print(i)
            break


if __name__ == "__main__":
    n, k = np.fromstring(read(), dtype=np.int32, sep=" ")
    a = set(read().split())
    main(n, k, a)

-        j = i -        while j: -            ok &= j % 10 not in a -            j //= 10 +        for j in str(i): +            ok &= j not in a -    a = np.fromstring(read(), dtype=np.int32, sep=" ") +    a = set(read().split())