n = int(input())
ans = max(0, min(n, 100) // 3 - 9 // 3)
for i in range(1 << 18):
    s = ""
    for j in range(9):
        s += str((i % 4) * 3)
        i //= 4
    if 100 <= int(s) <= n:
        ans += 1
print(ans)