import itertools

def calc_num(S,S_len):

  result = 0;

  l = [3,5,7];

  i = 3;

  while i <= S_len:

    for v in itertools.product(l,repeat=i):

      if int("".join(map(str,v))) <= S and list(set(v) & set(l)) == l:

        result = result + 1;

    i = i + 1;

  return result

  

S = list(map(int,eval(input())));

S_len = len(S);

S = int("".join(map(str, S)));

result = calc_num(S,S_len);

print(result)
import itertools

n = int(eval(input()))

target = ["7","5","3"]

c = 0

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

  for p in list(itertools.product(target,repeat=i)):

    if int("".join(list(p))) <= n and len(set(p))==3: c += 1

print(c)

    
import itertools


def calc_num(S, S_len):
    result = 0
    l = [3, 5, 7]
    i = 3
    while i <= S_len:
        for v in itertools.product(l, repeat=i):
            if int("".join(map(str, v))) <= S and list(set(v) & set(l)) == l:
                result = result + 1
        i = i + 1
    return result


S = list(map(int, eval(input())))
S_len = len(S)
S = int("".join(map(str, S)))
result = calc_num(S, S_len)
print(result)

import itertools

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

- -def calc_num(S, S_len): -    result = 0 -    l = [3, 5, 7] -    i = 3 -    while i <= S_len: -        for v in itertools.product(l, repeat=i): -            if int("".join(map(str, v))) <= S and list(set(v) & set(l)) == l: -                result = result + 1 -        i = i + 1 -    return result - - -S = list(map(int, eval(input()))) -S_len = len(S) -S = int("".join(map(str, S))) -result = calc_num(S, S_len) -print(result) +n = int(eval(input())) +target = ["7", "5", "3"] +c = 0 +for i in range(1, len(str(n)) + 1): +    for p in list(itertools.product(target, repeat=i)): +        if int("".join(list(p))) <= n and len(set(p)) == 3: +            c += 1 +print(c)