using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var p = new int[] { 0, 0, 0, 1, 1, 2, 2, 3, 3, 3 };
        var s = Console.ReadLine().Trim();
        var n = int.Parse(s);
        var sL = s.Length;
        var k = Pow(3, sL - 1);
        var ans = 0;
        for (int i = 1; i <= sL - 1; i++) ans +=(int) Pow(3, i);
        var a = 1;
        for (int i = 0; i < sL; i++)
        {
            var w = int.Parse(s[i].ToString());
            a *= p[w];
        }
        Console.WriteLine(ans + a);
    }
}
