n = int(input())
nn = 0
i = 357

while i <= n:
  s = str(i)
  if ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s) is False:
    if '3' in s:
      if '5' in s:
        if '7' in s:
          #print(i)
          nn += 1
  if i % 10 == 7:
    i += 6
  else:
    i +=2
print(nn)