N=int(eval(input()))



def dfs(s):

    if int(s)>N:

        return 0

    else:

        if all(s.count(c)>=1 for c in "753"):

            res=1

        else:

            res=0

        for c in "753":

            res+=dfs(s+c)

        return res



print((dfs("0")))
from sys import stdin

from collections import deque

def main():

    #入力

    readline=stdin.readline

    N=int(readline())



    #dfs

    count=0

    stack=deque(["0"])

    while len(stack)>=1:

        t=stack.pop()

        for s in "357":

            now=t+s

            if int(now)>N:

                break

            if ("7" in now) and ("5" in now) and ("3" in now):

                count+=1

            stack.append(now)

    

    print(count)



if __name__=="__main__":

    main()
N = int(eval(input()))


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


print((dfs("0")))

from sys import stdin
from collections import deque


def main():
    # 入力
    readline = stdin.readline
    N = int(readline())
    # dfs
    count = 0
    stack = deque(["0"])
    while len(stack) >= 1:
        t = stack.pop()
        for s in "357":
            now = t + s
            if int(now) > N:
                break
            if ("7" in now) and ("5" in now) and ("3" in now):
                count += 1
            stack.append(now)
    print(count)


if __name__ == "__main__":
    main()

-N = int(eval(input())) +from sys import stdin +from collections import deque -def dfs(s): -    if int(s) > N: -        return 0 -    else: -        if all(s.count(c) >= 1 for c in "753"): -            res = 1 -        else: -            res = 0 -        for c in "753": -            res += dfs(s + c) -        return res +def main(): +    # 入力 +    readline = stdin.readline +    N = int(readline()) +    # dfs +    count = 0 +    stack = deque(["0"]) +    while len(stack) >= 1: +        t = stack.pop() +        for s in "357": +            now = t + s +            if int(now) > N: +                break +            if ("7" in now) and ("5" in now) and ("3" in now): +                count += 1 +            stack.append(now) +    print(count) -print((dfs("0"))) +if __name__ == "__main__": +    main()