n=int(eval(input()))



def dfs(s):

    if int(s)>n:

        return 0

    ret=1 if all(s.count(c)>0 for c in "753") else 0

    for c in "753":

        ret+=dfs(s+c)

    return ret



print((dfs("0")))
n=int(eval(input()))



def dfs(s):

    if int(s)>n:

       return 0

    b=(all(map(s.count,"357")))

    for c in "357":

        b+=dfs(s+c)

    return b

print((dfs("0")))
n = int(eval(input()))


def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret


print((dfs("0")))

n = int(eval(input()))


def dfs(s):
    if int(s) > n:
        return 0
    b = all(map(s.count, "357"))
    for c in "357":
        b += dfs(s + c)
    return b


print((dfs("0")))

-    ret = 1 if all(s.count(c) > 0 for c in "753") else 0 -    for c in "753": -        ret += dfs(s + c) -    return ret +    b = all(map(s.count, "357")) +    for c in "357": +        b += dfs(s + c) +    return b