# -*- coding: utf-8 -*-

import numpy as np
import itertools

and_memo = {}


def list_subarray_sums(arr, length):
    cumsum = np.insert(np.cumsum(arr), 0, 0)
    for l in range(1, length + 1):
        for i in range(length - l + 1):
            yield cumsum[l + i] - cumsum[i]


def logical_and(arr, lenght, idx=0):
    if idx == lenght - 1:
        return arr[-1]
    if arr[idx] == 0:
        return 0

    key = tuple(arr[idx:])
    if key in and_memo:
        return and_memo[key]

    result = arr[idx] & logical_and(arr, lenght, idx + 1)
    and_memo[key] = result
    return result


if __name__ == '__main__':
    N, K = map(int, input().split(' '))
    A = np.array(list(map(int, input().split(' '))))

    sums = set(list_subarray_sums(A, N))
    combinations = itertools.combinations(sums, K)
    ands = map(lambda arr: logical_and(arr, K), combinations)

    print(max(ands))
