Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

C. Permute Digits

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.

It is allowed to leave *a* as it is.

Input

The first line contains integer *a* (1 ≤ *a* ≤ 10^{18}). The second line contains integer *b* (1 ≤ *b* ≤ 10^{18}). Numbers don't have leading zeroes. It is guaranteed that answer exists.

Output

Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.

The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.

Examples

Input

123

222

Output

213

Input

3921

10000

Output

9321

Input

4940

5000

Output

4940

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/22/2019 05:41:57 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|