N = int(input())

ans = 0
def dfs(s):
    global ans
    if int(s) > N:
        return
    if all(s.count(i) for i in '753'):
        ans += 1
        return
    for c in '753':
        dfs(s+c)
        
dfs('0')
print(ans)