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

(defn judge [n]
  (let [tmp (str n)]
    (if (and
          (<= 1 (count (filter #(= \5 %) tmp)))
          (<= 1 (count (filter #(= \7 %) tmp)))
          (<= 1 (count (filter #(= \3 %) tmp)))
          (zero? (count (remove #(or (= \5 %) (= \7 %) (= \3 %)) tmp))))
      true
      false)))


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


(->> (input)
  NaNaGoGo
  println)