(set! *unchecked-math* true)
(defn input []
  (let [[N M] (->> (clojure.string/split (read-line) #"\s")
                (map #(Integer/parseInt %)))]
    (letfn [(inner-input [x]
              (->> (repeatedly x read-line)
                (into []
                  (comp (map #(clojure.string/split % #"\s"))
                    (map (partial mapv #(Integer/parseInt %)))))))]
      (vector (inner-input N) (inner-input M)))))

(defn distance [A B]
  (unchecked-add-int
    (Math/abs (unchecked-subtract-int (A 0) (B 0)))
    (Math/abs (unchecked-subtract-int (A 1) (B 1)))))

(defn inner-map [C S]
  (->> C
    (map-indexed #(vector-of :int %1 (distance S %2)))
    reverse
    (apply min-key second)
    first
    inc))

(defn Checkpoints [[S C]]
  (transduce
    (comp (map (partial inner-map C))
      (map #(str % "\n")))
    str
    S))


(->> (input)
  Checkpoints
  println)