(defn input []
  (->> (repeatedly 2 read-line)
    (into [] (comp (mapcat #(clojure.string/split % #"\s"))
               (map #(Integer/parseInt %))))))

(defn TravelingAtCoDeer [[N & As]]
  (loop [As' (sort As)  result (int 0)]
    (if (= 1 (count As'))
      result
      (recur (rest As') (int (+ result (- (second As') (first As'))))))))

(->> (input)
  TravelingAtCoDeer
  println)