

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())

def dfs(X, bit, count):
    if X >= N:
        return count

    if bit == 7:
        count += 1

    count = dfs(X*10+7, bit|4, count)
    count = dfs(X*10+5, bit|2, count)
    count = dfs(X*10+3, bit|1, count)

    return count


count = dfs(0, 0, 0)
print(count)
