Lexicographically smallest ternary#3143

Lexicographically smallest ternary

1 second
64 megabytes
Medium

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 ).

Input

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

Output

Output the answer.

Examples

Example 1

Loading
Loading