Find the first year strictly greater than a given year whose digits are all different.
You are given a year . Your task is to find the smallest year greater than such that all digits in the year are pairwise distinct.
A year is called lucky if no digit appears more than once in its decimal representation. Starting from , check years in increasing order until you find the first lucky one.
Input Format
A single integer ().
Output Format
Print the minimum year strictly greater than whose decimal digits are all distinct.
Constraints
- The answer always exists within the reasonable range for the problem setting.
Example 1
Input
1987
Output
2013
Explanation
1988, 1989, 1990, ..., 2012 all contain repeated digits. The first year after 1987 with all distinct digits is 2013.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.