import sys

n = int(eval(input()))

if n < 357:

  print((0))

  sys.exit()



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'))) 
#!/usr/bin/env python3

import sys

import itertools



def solve(N: int):

    LEN = len(str(N))

    if LEN <= 2:

        print((0))

        return



    answer = 0

    for i in range(3,LEN+1):

        for num in list(itertools.product(['3','5','7'], repeat=i)):



            if num.count('3') >= 1 and num.count('5')>=1 and num.count('7') >=1 and int(''.join(num))<=N:

                answer +=1



    print(answer)

    return





def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    solve(N)



if __name__ == '__main__':

    main()

import sys

n = int(eval(input()))
if n < 357:
    print((0))
    sys.exit()


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")))

#!/usr/bin/env python3
import sys
import itertools


def solve(N: int):
    LEN = len(str(N))
    if LEN <= 2:
        print((0))
        return
    answer = 0
    for i in range(3, LEN + 1):
        for num in list(itertools.product(["3", "5", "7"], repeat=i)):
            if (
                num.count("3") >= 1
                and num.count("5") >= 1
                and num.count("7") >= 1
                and int("".join(num)) <= N
            ):
                answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()

+#!/usr/bin/env python3 - -n = int(eval(input())) -if n < 357: -    print((0)) -    sys.exit() +import itertools -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 +def solve(N: int): +    LEN = len(str(N)) +    if LEN <= 2: +        print((0)) +        return +    answer = 0 +    for i in range(3, LEN + 1): +        for num in list(itertools.product(["3", "5", "7"], repeat=i)): +            if ( +                num.count("3") >= 1 +                and num.count("5") >= 1 +                and num.count("7") >= 1 +                and int("".join(num)) <= N +            ): +                answer += 1 +    print(answer) +    return -print((dfs("0"))) +def main(): +    def iterate_tokens(): +        for line in sys.stdin: +            for word in line.split(): +                yield word + +    tokens = iterate_tokens() +    N = int(next(tokens))  # type: int +    solve(N) + + +if __name__ == "__main__": +    main()