def dfs(s):
    if int(s) > N:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        res += dfs(s + c)
    return res


N = int(input())
print(dfs('0'))