using System;
public class Program
{
public static void Main()
var numberOfElves = 3012210;
var section = (int)Math.Pow(3, (int)Math.Log(numberOfElves - 1, 3));
Console.WriteLine(numberOfElves - section + Math.Max(0, numberOfElves - 2 * section));
}