시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 89 16 5 25.000%

문제

중복 없는 수는 각 숫자(1, 2, 3, ..., 9)가 최대 한 번씩 등장하고, 숫자 0은 포함하지 않는 수이다. 따라서 중복 없는 수는 최대 9자리로 이루어질 수 있다. 중복 없는 수의 예시로는 9, 32, 489, 98761, 983245 등이 있다.

정수 N이 주어질 때, N보다 크면서 가장 작은 중복 없는 수를 출력하는 프로그램을 작성하라.

입력

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 정수 N(0 ≤ N ≤ 999,999,999)이 주어진다.

출력

각 테스트 케이스마다 답을 출력한다. 만약 답에 해당하는 수가 없는 경우는 0을 출력한다.

예제 입력 1

99
881
133
999999999

예제 출력 1

123
891
134
0
W3sicHJvYmxlbV9pZCI6IjExMDM3IiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiXHVjOTExXHViY2Y1IFx1YzVjNlx1YjI5NCBcdWMyMTgiLCJkZXNjcmlwdGlvbiI6IjxwPjxzdHJvbmc+XHVjOTExXHViY2Y1IFx1YzVjNlx1YjI5NCBcdWMyMTg8XC9zdHJvbmc+XHViMjk0IFx1YWMwMSBcdWMyMmJcdWM3OTAoMSwgMiwgMywgLi4uLCA5KVx1YWMwMCBcdWNkNWNcdWIzMDAgXHVkNTVjIFx1YmM4OFx1YzUyOSBcdWI0ZjFcdWM3YTVcdWQ1NThcdWFjZTAsIFx1YzIyYlx1Yzc5MCAwXHVjNzQwIFx1ZDNlY1x1ZDU2OFx1ZDU1OFx1YzljMCBcdWM1NGFcdWIyOTQgXHVjMjE4XHVjNzc0XHViMmU0LiBcdWI1MzBcdWI3N2NcdWMxMWMgXHVjOTExXHViY2Y1IFx1YzVjNlx1YjI5NCBcdWMyMThcdWIyOTQgXHVjZDVjXHViMzAwIDlcdWM3OTBcdWI5YWNcdWI4NWMgXHVjNzc0XHViOGU4XHVjNWI0XHVjOWM4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