Legendary mathematics teacher Yuriy Petrovych has invented an entertaining game with numbers. He takes any integer, converts it to its binary representation—a sequence of zeros and ones that always starts with one. For example, the decimal number is written in binary as (1 \times 2^4 + 0 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0).
Next, he cyclically shifts the digits of this binary number: the last digit moves to the front, and all other digits shift one position to the right. He writes each resulting sequence in a column. He observed that no matter the original number, these binary sequences eventually start to repeat.
Finally, Yuriy Petrovych finds the maximum among the written numbers and converts it back to decimal, taking this as the result of the manipulations. For , the list of sequences is:
10011 \ 11001 \ 11100 \ 01110 \ 00111 \ 10011 \ldots
and the result of the game is 1 \times 2^4 + 1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 0 \times 2^0 = 28.
Since this game distracts Yuriy Petrovych from working with his exceptionally talented students, your task is to write a program to help him obtain the result quickly, without tedious manual calculations.
The input consists of a single integer (0 \le N \le 32767).
Your program should output a single integer: the result of the game.
Example 1