import math
combination = int(input("Enter the number of Combination: "))
num = [[0]*50 for _ in range(50)]
for i in range(0, combination):
num[i] = int(input("Enter (int) Digit %d: " % (i+1)))
limit = int(input("Enter the limit: "))
#iterate from 1 to limit
for i in range(1, limit+1):
copyNum = i
count = 0
flag = 0
#check each digit starting from last digit
while(copyNum != 0):
count += 1
lastDigit = copyNum % 10
for j in range(0, combination):
if(num[j] == lastDigit):
flag += 1
copyNum = math.floor(copyNum / 10)
if(count == flag):
print(i, end=" ")