(defn input []
  (Integer/parseInt (read-line)))

(defn judge [n]
  (let [tmp (str n)
        Five (count (filter #(= \5 %) tmp))
        Seven (count (filter #(= \7 %) tmp))
        Three (count (filter #(= \3 %) tmp))
        Sum (count tmp)]
    (if (and
          (<= 1 Five)
          (<= 1 Seven)
          (<= 1 Three)
          (= Sum (+ Five Seven Three)))
      true
      false)))


(defn NaNaGoGo [N]
  (count (filter judge (range 1 (inc N)))))


(->> (input)
  NaNaGoGo
  println)