- permutations 함수를 사용하여 모든 경우의 수를 만들어 냄.
- for문과 if문을 사용하여 완전 탐색.
from itertools import permutations
def solution() :
a, b = input().split()
sub = list(map(lambda x : ''.join(x), permutations(a)))
res = -1
for s in sub :
if int(b) >= int(s) and s[0] != '0' :
res = max(res, int(s))
print(res)
solution()