N = int(input())

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

    for c in "753":
        cnt += dfs(s + c)
    
    return cnt

print(dfs("0"))