The Law of the Jungle
Akela, the formidable lone gray wolf, rose to lead the pack through his strength and cunning. For twelve years, he guided the pack on hunts, ensuring none fell into traps.
As time passed, Akela aged and weakened. The lame tiger, Shere Khan, gained influence over the younger wolves, who often followed him. Akela, lacking his former strength, could no longer assert his authority to prevent this.
Over the years, Akela began to forget parts of the Jungle Law. However, he could not violate it, as the Law had become instinctual to him; he also remembered its checksum clearly.
The younger wolves, along with Shere Khan, sought to amend and expand the Jungle Law. Their motives were unclear, but fortunately, Hathi himself rejected these changes, allowing the Jungle to remain at peace.
Yet, it is intriguing to consider how the main Law might appear with the proposed amendments, knowing that its checksum remained unchanged.
Input
A natural number n
(1 ≤ n ≤ 10^100
) representing the Law of the Jungle.
Output
Output the smallest natural number m
> n
that has the same checksum (sum of digits) as the number n
—the version of the Jungle Law as envisioned by the opposition wolves led by Shere Khan.