X = int(input())
ans = []
for i in range(357, X):
  if i > X:
    break
  a = str(i)
  if a[-1] is not '3' and a[-1] is not '5' and a[-1] is not '7':
    continue
  a = ''.join(sorted(list(set(str(i)))))
  if a == '357':
    ans.append(i)
print(len(ans))