module M = Map.Make (
    struct
       type t = int * int
       let compare (a1, a2) (b1, b2) = compare (a1 lsr a2) (b1 lsr b2)
    end)
let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let add key v map = M.add key (v + try M.find key map with _ -> 0) map in
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let list = split (read_line ()) in
        let map = List.fold_left (fun map a -> add (a, 0) 1 map) M.empty list in
        let rec loop rest map =
            if rest = 0 then map else
                let ((a1, a2) as mk, mv) = M.max_binding map in
                if rest < mv then (
                    let map = M.remove mk map in
                    let map = add mk (mv - rest) map in
                    let map = add (a1, a2 + 1) rest map in
                    map
                ) else (
                    let map = M.remove mk map in
                    let map = add (a1, a2 + 1) mv map in
                    loop (rest - mv) map
                )
        in
        let map = loop m map in
        let r = M.fold (fun (a1, a2) v acc -> acc + v * (a1 lsr a2)) map 0 in
        Printf.printf "%d\n" r
    in
    main ()