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

(defn inner-func [n ns]
  (eduction
    (map #(take % ns))
    (map (partial apply +))
    (map (partial + n))
    (range (inc (count ns)))))

(defn SAS [[[N K] As]]
  (loop [as As l nil]
    (if (empty? as)
      (let [tmp (->> l
                  sort
                  (take-last K))]
        (apply bit-and tmp))
      (recur (rest as) (concat l (inner-func (first as) (rest as)))))))

(->> (input)
  SAS
  println)