### BUGGY CODE ###

nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

all_seisuuretu = []

for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            all_seisuuretu.append(seisuuretu[start:end])

list_max = []
beautiful_list = []
for pattern in all_seisuuretu:
    temp_pattern = bin(sum(pattern))[2:]
    beautiful_list.append(temp_pattern)
    list_max.append(len(temp_pattern))

list_max = -max(list_max)

status = True
while status == True:
    temp = []
    count = 0
    len_all = 0
    for len_count in beautiful_list:
        len_all += len(len_count)
    if int(nk[1]) <= len_all / len(beautiful_list):
        for i in beautiful_list:
            try:
                if int(i[list_max]) == 1:
                    count += 1
                    temp.append(i)
            except:
                continue
        if count > int(nk[1]):
            list_max += 1
            beautiful_list = temp
        elif count == int(nk[1]):
            beautiful_list = temp
            num_count = True
            for num in beautiful_list:
                if num_count == True:
                    ronriseki = int(num, 2)
                else:
                    ronriseki = ronriseki & int(num, 2)
                num_count = False
            print(ronriseki)
            status = False
        elif list_max == -1:
            num_count = True
            for num in beautiful_list:
                if num_count == True:
                    ronriseki = int(num, 2)
                else:
                    ronriseki = ronriseki & int(num, 2)
                num_count = False
            print(ronriseki)
            status = False
        else:
            list_max += 1
    else:
        list_max += 1


### FIXED CODE ###

nk = input().split()
seisuuretu_2 = input().split()
nk1 = int(nk[1])

#seisuuretu = [int(i) for i in seisuuretu_2]
seisuuretu = list(map(int, seisuuretu_2))

list_max = set()
beautiful_list = []
for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            temp_pattern = bin(sum(seisuuretu[start:end]))[2:]
            beautiful_list.append(temp_pattern)
            list_max |= {len(temp_pattern),}

list_max = -max(list_max)

status = True
while status == True:
    temp = []
    count = 0
    for i in beautiful_list:
        try:
            if i[list_max] == "1":
                count += 1
                temp.append(i)
        except:
            continue
    if count > nk1:
        list_max += 1
        beautiful_list = temp
    elif count == nk1:
        num_count = True
        for num in temp:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        exit()
        status = False
    elif list_max == -1:
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        exit()
        status = False
    else:
        list_max += 1