n = int(input())
def dfs(s): #sで始まる753数
    if int(s)>n:
        return 0
    ret = 1 if all(s.count(f) for f in "753") else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))