from collections import deque
A,B=map(int,input().split())
ll=list(str(A))
visit=[False for _ in range(10)]
stack=[]
sy=[]
def back_t():
if len(sy)==len(ll):
a=''.join(sy)
if len(a.lstrip("0")) ==len(ll):
stack.append(int(a))
for i in range(len(ll)):
ll[i]=int(ll[i])
if not visit[i]:
visit[i]=True
sy.append(str(ll[i]))
back_t()
sy.pop()
visit[i]=False
back_t()
for mx in sorted(stack,reverse=True):
if mx<B:
print(mx)
exit()
print(-1)
'알고리즘 > 백준' 카테고리의 다른 글
백준-18108번(1998년생인 내가 태국에서는 2541년생?!)-python3 (0) | 2023.12.01 |
---|---|
백준-17298번(오큰수)-python3 (0) | 2023.12.01 |
백준-16922번(로마 숫자 만들기)-python3 (0) | 2023.12.01 |
백준-15654번(N과 M(5))-python3 (0) | 2023.12.01 |
백준-15652번(N과 M(4))-python3 (0) | 2023.12.01 |