
n=int(input())



def dfs(s):
    ans=0
    if int(s)>n:
        return 0
    else:
        ans+=all(map(s.count,"357"))
        for i in "357":
            ans+=dfs(s+i)
    return ans
print(dfs("0"))