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 dfs(s):

    res = 0

    if int(s) > N: return res

    if all(c in s for c in '753'): res += 1

    for v in '753': res += dfs(s + 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 dfs(s):
    res = 0
    if int(s) > N:
        return res
    if all(c in s for c in "753"):
        res += 1
    for v in "753":
        res += dfs(s + 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): +def dfs(s): -    if check(x): +    if int(s) > N: +        return res +    if all(c in s for c in "753"): -    if x <= N: -        for v in 3, 5, 7: -            res += dfs(10 * x + v) +    for v in "753": +        res += dfs(s + v) -print((dfs(0))) +print((dfs("0")))