Imports System.Collections.Generic
Imports System.Console

Module Program
    Dim N As Integer = NextInt()
    Dim K As Integer = NextInt()
    Dim D(K - 1) As Integer

    Sub Main()
        For i As Integer = 0 To UBound(D)
            D(i) = NextInt()
        Next

        For i As Integer = 0 To Integer.MaxValue
            DFS("", i)
        Next
    End Sub

    Sub DFS(s As String, m As Integer)
        If s <> "" AndAlso CInt(s) >= N Then
            WriteLine(s)
            End
        End If

        If s.Length = m Then Return

        For i As Integer = 0 To 9
            If Not Contains(D, i) Then DFS(i.ToString & s, m)
        Next
    End Sub

    Function Contains(A As Integer(), x As Integer) As Boolean
        For Each Ai As Integer In A
            If Ai = x Then Return True
        Next
        Return False
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module
