시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 32 MB 6852 2398 1914 34.775%

문제

어느날, 미르코는 우연히 길거리에서 양수 N을 보았다. 미르코는 30이란 수를 존경하기 때문에, 그는 길거리에서 찾은 수에 포함된 숫자들을 섞어 30의 배수가 되는 가장 큰 수를 만들고 싶어한다.

미르코를 도와 그가 만들고 싶어하는 수를 계산하는 프로그램을 작성하라.

입력

N을 입력받는다. N는 최대 105개의 숫자로 구성되어 있으며, 0으로 시작하지 않는다.

출력

미르코가 만들고 싶어하는 수가 존재한다면 그 수를 출력하라. 그 수가 존재하지 않는다면, -1을 출력하라.

예제 입력 1

30

예제 출력 1

30

예제 입력 2

102

예제 출력 2

210

예제 입력 3

2931

예제 출력 3

-1
W3sicHJvYmxlbV9pZCI6IjEwNjEwIiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiMzAiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzViNFx1YjI5MFx1YjBhMCwgXHViYmY4XHViOTc0XHVjZjU0XHViMjk0IFx1YzZiMFx1YzVmMFx1ZDc4OCBcdWFlMzhcdWFjNzBcdWI5YWNcdWM1ZDBcdWMxMWMgXHVjNTkxXHVjMjE4IE5cdWM3NDQgXHViY2Y0XHVjNTU4XHViMmU0LiBcdWJiZjhcdWI5NzRcdWNmNTRcdWIyOTQgMzBcdWM3NzRcdWI3ODAgXHVjMjE4XHViOTdjIFx1Yzg3NFx1YWNiZFx1ZDU1OFx1YWUzMCBcdWI1NGNcdWJiMzhcdWM1ZDAsIFx1YWRmOFx1YjI5NCBcdWFlMzhcdWFjNzBcdWI5YWNcdWM1ZDBcdWMxMWMgXHVjYzNlXHVjNzQwIFx1YzIxOFx1YzVkMCBcdWQzZWNcdWQ1NjhcdWI0MWMgXHVjMjJiXHVjNzkwXHViNGU0XHVjNzQ0IFx1YzExZVx1YzViNCAzMFx1Yzc1OCBcdWJjMzBcdWMyMThcdWFjMDAgXHViNDE4XHViMjk0IFx1YWMwMF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