Many facilities use password authentication, and the JAG office is one of them. You need a password to enter the office. A password is a string of N digits from '0' to '9', and it is changed on a regular basis. Taro, a staff member of the JAG security division, decided to build a new password from the old one with the following rules.
- The new password has the same length N as the old one, and each digit appears at most once in it. It can have a leading zero. (The old password may contain the same digit twice or more.)
- Subject to the rule above, the new password maximizes the difference from the old password. The difference is defined below.
- If two or more candidates remain, the one with the smallest value when read as an integer is selected.
The difference between two passwords is min(∣a−b∣, 10N−∣a−b∣), where a and b are the integers represented by the two passwords. For example, the difference between "11" and "42" is 31, and the difference between "987" and "012" is 25.
Given the old password, write a program that computes the new password.