N = int(input()) SN = str(N) cnt = 0 if N < 100: print((N-9)//3) exit() if int(SN[0]) < 3: N2 = [3] * (len(SN) - 1) else: N2 = [] while N > 0: N2.append((N%10)//3) N //= 10 ans = 30 tmp = 0 for i in reversed(N2): tmp *= 4 tmp += i ans += tmp - 15 print(ans)