from itertools import product



def ans():

  N = int(eval(input()))

  cnt = 0

  for i in range(3, 11):

    for p in product(["3", "5", "7"], repeat = i):

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

        p = int("".join(p))

        if(p <= N):

          cnt += 1

  print(cnt)

ans()
from itertools import product



N = int(eval(input()))

cnt = 0

for i in range(3,len(str(N))+1):

  for p in product(["3", "5", "7"], repeat = i):

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

      if(int("".join(p)) <= N):

        cnt += 1

print(cnt)
from itertools import product


def ans():
    N = int(eval(input()))
    cnt = 0
    for i in range(3, 11):
        for p in product(["3", "5", "7"], repeat=i):
            if "3" in p and "5" in p and "7" in p:
                p = int("".join(p))
                if p <= N:
                    cnt += 1
    print(cnt)


ans()

from itertools import product

N = int(eval(input()))
cnt = 0
for i in range(3, len(str(N)) + 1):
    for p in product(["3", "5", "7"], repeat=i):
        if "3" in p and "5" in p and "7" in p:
            if int("".join(p)) <= N:
                cnt += 1
print(cnt)

- -def ans(): -    N = int(eval(input())) -    cnt = 0 -    for i in range(3, 11): -        for p in product(["3", "5", "7"], repeat=i): -            if "3" in p and "5" in p and "7" in p: -                p = int("".join(p)) -                if p <= N: -                    cnt += 1 -    print(cnt) - - -ans() +N = int(eval(input())) +cnt = 0 +for i in range(3, len(str(N)) + 1): +    for p in product(["3", "5", "7"], repeat=i): +        if "3" in p and "5" in p and "7" in p: +            if int("".join(p)) <= N: +                cnt += 1 +print(cnt)