import itertools

n  = int(input())

max_m = len(str(n))

ans = 0

for m in range(1,max_m+1):
  for i in range(1, m):
    for j in range(1, m-i):
      k = m-i-j
      ls = ['7']*i+['5']*j+['3']*k
      ss = set()
      for l in itertools.permutations(ls):
        s = ''.join(l)
        s = int(s)
        if s in ss:
          continue
        elif s <= n:
          ans += 1
          # print(s)
          ss.add(s)
        else:
          ss.add(s)
print(ans)