ret = 0

n = int(input())

def dfs(i, f):
    if i > n:
        return
    if f == 7:
        global ret
        ret += 1
    dfs(i*10+3, f|1)

    dfs(i*10+5, f|2)
    dfs(i*10+7, f|4)

dfs(0, 0)
print(ret)