s=input()

def dfs(i):
    if int(i) > int(s):
        return 0
    res = 1 if all(i.count(c) > 0 for c in ("753")) else 0

    for t in "753":
        res += dfs(i+t)
    
    return res

print(dfs("0"))