import sys

import numpy as np

from numba import njit, i4

read = sys.stdin.readline





@njit((i4, i4, i4[:]), cache=True)

def main(n, k, a):

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

        ok = 1

        j = i

        while j:

            m = j % 10

            for l in a:

                if m == l:

                    ok = 0

            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

from numba import njit, i4

read = sys.stdin.readline





if sys.argv[-1] == 'ONLINE_JUDGE':

    from numba.pycc import CC

    cc = CC('unko')



    @cc.export('main', '(i4, i4, i4[:])')

    def main(n, k, a):

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

            ok = 1

            j = i

            while j:

                m = j % 10

                for l in a:

                    if m == l:

                        ok = 0

                j //= 10

            if ok:

                print(i)

                break

    cc.compile()

    exit()





if __name__ == '__main__':

    from unko import 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
from numba import njit, i4

read = sys.stdin.readline


@njit((i4, i4, i4[:]), cache=True)
def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = 1
        j = i
        while j:
            m = j % 10
            for l in a:
                if m == l:
                    ok = 0
            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
from numba import njit, i4

read = sys.stdin.readline
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba.pycc import CC

    cc = CC("unko")

    @cc.export("main", "(i4, i4, i4[:])")
    def main(n, k, a):
        for i in np.arange(n, 100000):
            ok = 1
            j = i
            while j:
                m = j % 10
                for l in a:
                    if m == l:
                        ok = 0
                j //= 10
            if ok:
                print(i)
                break

    cc.compile()
    exit()
if __name__ == "__main__":
    from unko import main

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

+if sys.argv[-1] == "ONLINE_JUDGE": +    from numba.pycc import CC +    cc = CC("unko") -@njit((i4, i4, i4[:]), cache=True) -def main(n, k, a): -    for i in np.arange(n, 100000): -        ok = 1 -        j = i -        while j: -            m = j % 10 -            for l in a: -                if m == l: -                    ok = 0 -            j //= 10 -        if ok: -            print(i) -            break +    @cc.export("main", "(i4, i4, i4[:])") +    def main(n, k, a): +        for i in np.arange(n, 100000): +            ok = 1 +            j = i +            while j: +                m = j % 10 +                for l in a: +                    if m == l: +                        ok = 0 +                j //= 10 +            if ok: +                print(i) +                break +    cc.compile() +    exit() +if __name__ == "__main__": +    from unko import main -if __name__ == "__main__":