#C3908. Next Greater Number

    ID: 47387 Type: Default 1000ms 256MiB

Next Greater Number

Next Greater Number

You are given a positive integer \(N\). Your task is to find the smallest number greater than \(N\) that can be formed by rearranging its digits. If no such number exists, output -1.

For example, if \(N = 123\), one possible rearrangement that is greater than 123 is 132, which is the smallest greater number. However, if \(N = 321\), no rearrangement can produce a number greater than 321, so the output should be -1.

Input/Output Format: The input is read from standard input, and the output should be printed to standard output.

Hint: You might want to use an algorithm similar to finding the next lexicographical permutation.

inputFormat

The input consists of a single line containing a positive integer \(N\) (\(1 \leq N \leq 10^{18}\)).

outputFormat

Output a single integer which is the smallest number greater than \(N\) formed by rearranging its digits. If no such number exists, output -1.

## sample
123
132