# 解説放送

def check(var):

    in_range = var <= N

    all_num_in = all(c in str(var) for c in '753')

    return in_range and all_num_in





def dfs(x):

    res = 0

    if check(x):

        res += 1

    if x <= N:

        res += dfs(10 * x + 3)

        res += dfs(10 * x + 5)

        res += dfs(10 * x + 7)

    return res





N = int(eval(input()))

print((dfs(0)))

# 解説放送

def dfs(x):

    if x > N: return 0

    res = 1 if all(c in str(x) for c in '753') else 0

    for v in 3, 5, 7:

        res += dfs(10 * x + v)

    return res





N = int(eval(input()))

print((dfs(0)))

# 解説放送
def check(var):
    in_range = var <= N
    all_num_in = all(c in str(var) for c in "753")
    return in_range and all_num_in


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


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

# 解説放送
def dfs(x):
    if x > N:
        return 0
    res = 1 if all(c in str(x) for c in "753") else 0
    for v in 3, 5, 7:
        res += dfs(10 * x + v)
    return res


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

-def check(var): -    in_range = var <= N -    all_num_in = all(c in str(var) for c in "753") -    return in_range and all_num_in - - -    res = 0 -    if check(x): -        res += 1 -    if x <= N: -        res += dfs(10 * x + 3) -        res += dfs(10 * x + 5) -        res += dfs(10 * x + 7) +    if x > N: +        return 0 +    res = 1 if all(c in str(x) for c in "753") else 0 +    for v in 3, 5, 7: +        res += dfs(10 * x + v)