N = int(input())
count=0
if N>777777777:
  N = 7777777777
for i in range(333,N+1):
  X = str(i)
  a3 = X.count("3")
  a5 = X.count("5")
  a7 = X.count("7")
  if(a3>0 and a5>0 and a7>0 and a3+a5+a7==len(X)):
    count+=1
print(count)