We’re preparing your current view and syncing the latest data.
You are given a year (a positive integer). Your task is to find the next year after the given one such that all digits of the year are distinct.
More formally, given a year y, find the smallest integer greater than y such that no digit appears more than once in its decimal representation.
A single integer y (1000 ≤ y ≤ 9000).
Output the smallest year greater than y with all distinct digits.
1000 ≤ y ≤ 9000
Example 1
Input
1987
Output
2013
Explanation
2013 is the next year after 1987 with all distinct digits.