Next Unique-Digit Number

No attempts yetTime limit1sMemory limit256 MB

Problem

A unique-digit number uses each digit from 1 to 9 at most once and never uses 0. Examples include 9, 32, 489, 98761, and 983245. Such numbers have at most 9 digits.

Given an integer NN, print the smallest unique-digit number strictly greater than NN. If no such number exists, print 0.

Input

The input has several test cases. Each test case is one line with an integer NN (0N999,999,9990 \le N \le 999,999,999).

Output

For each test case, print the answer on its own line. Print 0 when no valid number exists.