eolymp
bolt
Try our new interface for solving problems
Problems

Calculator

Calculator

Time limit 1 second
Memory limit 128 MiB

Ilya's calculator performs two actions: multiplies the current number by three and adds one to it. The calculator now shows the number 1. Help Ilya to determine the smallest number of operations, after which he will get the number n.

Input data

One integer n~(10 \le n \le 10^9).

Output data

Print the minimum number of operations.

Examples

Input example #1
1447
Output example #1
16