N = int(input())

def dfs(x):
    if int(x) > N:
        return 0

    ans = 1 if all(x.count(c)  for c in "753") > 0 else 0

    for n in "753":
        ans += dfs(x+n)

    return ans


print(dfs("0"))