N = int(input())

dic = [3, 5, 7]

ans = list()
def dfs(s):
    if s:
        if int(s) < N:
            if len(set(s)) == 3:
                ans.append(s)
        else:
            return
    dfs(s+"3")
    dfs(s+"5")
    dfs(s+"7")

dfs("")
print(len(ans))
