Page not loading? Try clicking here.
Placeholder

#2896

CESTA (LAKA) 1s 32MB

Problems

One morning, completely by chance, Mirko found a positive integer N in the middle of the street. Since Mirko adores the number 30, he wants to know the maximum multiple of the number 30 that can be obtained by shuffling the digits of the number he found in the street.

Help our hero and write a programme that calculates that number (if it exists).


Input

The first and only line of input contains the integer N, equal or less than 105.


Example #1

30
30

Example #2

102
210

Example #3

2931
-1


Source

COCI 2014/2015 contest4 1 변형

You must sign in to write code.