Lexicographically smallest ternary#3143

Lexicographically smallest ternary

1 Sekunde
64 Megabyte
Mittel

All numbers between and are written in base-three numeral system, without leading zeros. Each number is given on a separate line. Then, the resulting lines are sorted lexicographically. Which number will be first?

The numbers and are given in decimal, and the answer should also be provided in decimal.

For example, if A = 2 and B = 12:

In this case, the answer will be (since in base three it is written as ).

Eingabe

Natural numbers and are given (1 \leq A \leq B \leq 10^{15}).

Ausgabe

Output the answer.

Beispiele

Beispiel 1

Loading
Loading