N = int(eval(input()))





def dfs(s):

    if int(s) > N:

        return 0

    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:

        ret = 1

        # print(s)

    else:

        ret = 0

    ret += dfs(s + "7")

    ret += dfs(s + "5")

    ret += dfs(s + "3")

    return ret





print((dfs("0")))



N = int(eval(input()))





def dfs(x):

    if x > N:

        return 0

    s = str(x)

    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:

        ret = 1

        # print(x)

    else:

        ret = 0

    ret += dfs(10 * x + 7)

    ret += dfs(10 * x + 5)

    ret += dfs(10 * x + 3)

    return ret





print((dfs(0)))



N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        # print(s)
    else:
        ret = 0
    ret += dfs(s + "7")
    ret += dfs(s + "5")
    ret += dfs(s + "3")
    return ret


print((dfs("0")))

N = int(eval(input()))


def dfs(x):
    if x > N:
        return 0
    s = str(x)
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        # print(x)
    else:
        ret = 0
    ret += dfs(10 * x + 7)
    ret += dfs(10 * x + 5)
    ret += dfs(10 * x + 3)
    return ret


print((dfs(0)))

-def dfs(s): -    if int(s) > N: +def dfs(x): +    if x > N: +    s = str(x) -        # print(s) +        # print(x) -    ret += dfs(s + "7") -    ret += dfs(s + "5") -    ret += dfs(s + "3") +    ret += dfs(10 * x + 7) +    ret += dfs(10 * x + 5) +    ret += dfs(10 * x + 3) -print((dfs("0"))) +print((dfs(0)))