program atcoder
    implicit none
    integer(8) :: n,k,i,ans,t
    integer(8) q(3_8**10+6)
    integer true(3_8**10+6)    
    read*,n
    ans = 0
    i = 1
    q(i) = 0
    true(i) = 0
    do while(i>0)
      k = q(i)
      t = true(i)
      i = i - 1
      if(k<=n .and. t==7)then
        ans = ans + 1
      endif
      if(k*10<=n)then
        i = i+1
        q(i) = k*10 + 3
        true(i) = or(t,1)
        i = i+1
        q(i) = k*10 + 5
        true(i) = or(t,2)
        i = i+1
        q(i) = k*10 + 7
        true(i) = or(t,4)
      endif
    enddo
    write(*,'(I0)')ans
!----------------------functions--------------------------
contains

end program atcoder