Scanf.scanf "%d %d" (fun n k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let d = Array.make (n + 1) 0 in
    for i = 1 to n do
        d.(i) <- d.(i - 1) + a.(i - 1)
    done;

    let s = Array.make (n * (n + 1) / 2) 0 in
    let rec loop_i i idx =
        let rec loop_j j idx =
            if j > n then loop_i (i + 1) idx else
                let () = s.(idx) <- d.(j) - d.(i) in
                loop_j (j + 1) (idx + 1)
        in
        if i = n then () else
            loop_j (i + 1) idx
    in
    loop_i 0 0;

    Array.sort (fun a b -> compare b a) s;

    let rec loop i acc =
        if i = k then acc else
            loop (i + 1) (acc land s.(i))
    in
    loop 0 (-1) |> Printf.printf "%d\n"
)