implicit none
integer(16) N
read*,N
print"(i0)",dfs(.false.,.false.,.false.,0_16)

contains

recursive function dfs(a,b,c,num)result(res)
  implicit none
  logical,intent(in)::a,b,c
  integer(16),intent(in)::num
  integer::res
  res=0
  if(num<=N)then
    if(a.and.b.and.c)res=1
    res = res + dfs(.true., b, c, num*10 + 7)
    res = res + dfs( a,.true., c, num*10 + 5)
    res = res + dfs( a, b,.true., num*10 + 3)
  endif
  return
end function
end