N = input().rstrip() ans = 0 if len(N) <= 2: ans = int(N) // 3 - 3 else: a = [1] carry = False for v in N: if carry: for i in range(len(a)): a[i] *= 4 else: for i in range(len(a) - 1): a[i] *= 4 if int(v) % 3 == 0: a[-1] *= int(v) // 3 a.append(1) else: a[-1] *= int(v) // 3 + 1 carry = True ans = sum(a) + 14 print(ans)