N = int(input())
cnt = 0
for i in range(357, N):
  l = map(int, list(str(i)))
  a_3,  a_5, a_7 = False, False, False
  for j in l:
    if j == 3:
      a_3 = True
    elif j == 5:
      a_5 = True
    elif j == 7:
      a_7 = True
    else:
      break
  if a_3 == a_5 == a_7 == True:
    cnt += 1
print(cnt)