import itertools





def solve():



    N = int(eval(input()))



    num = str(N)

    com = []

    com.append(('3', '5', '7'))

    com.append(('3', '5', '7'))

    res = 0

    dig = len(num)

    for x in range(3, dig+1):

        com.append(('3', '5', '7'))



        temp = list(itertools.product(*com))



        tempanswer = [i for i in temp if all(i.count(k) for k in '753')]

        answer = [int("".join(y)) for y in tempanswer if int("".join(y)) <= N]



        res = len(answer) + res

    print(res)





solve()
import itertools

if __name__ == '__main__':

  

  N = eval(input())

  n = int(N)

  count = 0

  for i in range(0, len(N)):



    temp = itertools.product(["3", "5", "7"], repeat=i+1)

    for j in temp:

      s = "".join(j)

      

      if ("3" in s and "5" in s and "7" in s and int(s) <= n):

        count += 1

  

  print(count)
import itertools


def solve():
    N = int(eval(input()))
    num = str(N)
    com = []
    com.append(("3", "5", "7"))
    com.append(("3", "5", "7"))
    res = 0
    dig = len(num)
    for x in range(3, dig + 1):
        com.append(("3", "5", "7"))
        temp = list(itertools.product(*com))
        tempanswer = [i for i in temp if all(i.count(k) for k in "753")]
        answer = [int("".join(y)) for y in tempanswer if int("".join(y)) <= N]
        res = len(answer) + res
    print(res)


solve()

import itertools

if __name__ == "__main__":
    N = eval(input())
    n = int(N)
    count = 0
    for i in range(0, len(N)):
        temp = itertools.product(["3", "5", "7"], repeat=i + 1)
        for j in temp:
            s = "".join(j)
            if "3" in s and "5" in s and "7" in s and int(s) <= n:
                count += 1
    print(count)

- -def solve(): -    N = int(eval(input())) -    num = str(N) -    com = [] -    com.append(("3", "5", "7")) -    com.append(("3", "5", "7")) -    res = 0 -    dig = len(num) -    for x in range(3, dig + 1): -        com.append(("3", "5", "7")) -        temp = list(itertools.product(*com)) -        tempanswer = [i for i in temp if all(i.count(k) for k in "753")] -        answer = [int("".join(y)) for y in tempanswer if int("".join(y)) <= N] -        res = len(answer) + res -    print(res) - - -solve() +if __name__ == "__main__": +    N = eval(input()) +    n = int(N) +    count = 0 +    for i in range(0, len(N)): +        temp = itertools.product(["3", "5", "7"], repeat=i + 1) +        for j in temp: +            s = "".join(j) +            if "3" in s and "5" in s and "7" in s and int(s) <= n: +                count += 1 +    print(count)