N = input()
 
ans = 0
def dfs(m):
    global ans
    if len(set(m))==3 and int(m)<=int(N):
        ans+=1
        
    if len(m)<len(N):
        for i in "357":
            dfs(m+i)
dfs("")
print(ans)