def solution(X, Y):
xy = list(set(list(X))&set(list(Y)))
x = {i:X.count(i) for i in xy}
for i in xy:
if x[i] > Y.count(i):
x[i] = Y.count(i)
num = []
for i,j in x.items():
n = [str(i)]*j
num += n
if num == []:
return "-1"
elif list(set(num)) == ["0"]:
return "0"
num.sort(reverse=True)
answer = ''.join(num)
return answer