시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 704 337 289 50.348%

문제

정수 X가 주어졌을 때, X와 구성이 같으면서 X보다 큰 수 중 가장 작은 수를 출력한다.

수의 구성이 같다는 말은, 수를 이루고 있는 각 자리수가 같다는 뜻이다. 예를 들어, 123과 321은 수의 구성이 같다. 하지만, 123과 432는 구성이 같지 않다.

입력

첫째 줄에 X가 주어진다. (1 ≤ X ≤ 999999) X는 0으로 시작하지 않는다.

출력

첫째 줄에 결과를 출력한다. 만약 그러한 숫자가 없는 경우에는 0을 출력한다.

예제 입력 1

156

예제 출력 1

165
W3sicHJvYmxlbV9pZCI6IjI5OTIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQwNmNcdWJhNzRcdWMxMWMgXHVjNzkxXHVjNzQwIFx1YzIxOCIsImRlc2NyaXB0aW9uIjoiPHA+XHVjODE1XHVjMjE4IFhcdWFjMDAgXHVjOGZjXHVjNWI0XHVjODRjXHVjNzQ0IFx1YjU0YywgWFx1YzY0MCBcdWFkNmNcdWMxMzFcdWM3NzQgXHVhYzE5XHVjNzNjXHViYTc0XHVjMTFjIFhcdWJjZjRcdWIyZTQgXHVkMDcwIFx1YzIxOCBcdWM5MTEgXHVhYzAwXHVjN2E1IFx1Yzc5MVx1Yzc0MCBcdWMyMThcdWI5N2MgXHVjZDljXHViODI1XHVkNTVjXHViMmU0LjxcL3A+XHJcblxyXG48cD5cdWMyMThcdWM3NTggXHVhZDZjXHVjMTMxXHVjNzc0IFx1YWMxOVx1YjJlNFx1YjI5NCBcdWI5ZDBcdWM3NDAsIFx1YzIxOFx1Yjk3YyBcdWM3NzRcdWI4ZThcdWFjZTAgXHVjNzg4XHViMjk0IFx1YWMwMSBcdWM3OTBcdWI5YWNcdWMyMThcdWFjMDAgXHVhYzE5XHViMmU0XHViMjk0IFx1YjczYlx1Yzc3NFx1YjJlNC4gXHVjNjA4XHViOTdjIFx1YjRlNFx1YzViNCwgMTIzXHVh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