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

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

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

(->> (input)
  SAS
  println)