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:

        for v in 3, 5, 7:

            res += dfs(10 * x + v)

    return res





N = int(eval(input()))

print((dfs(0)))

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(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:
        for v in 3, 5, 7:
            res += dfs(10 * x + v)
    return res


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

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(eval(input()))
print((dfs(0)))

-    in_range = var <= N -    all_num_in = all(c in str(var) for c in "753") -    return in_range and all_num_in +    return (0 <= var <= N) and all(c in str(var) for c in "753")