def check(var):
    return (0 <= var < N) and all(c in str(var) for c in '753')


def dfs(x):
    res = 0
    if check(x): res += 1
    if x <= N:
        for v in 3, 5, 7:
            res += dfs(10 * x + v)
    return res


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