#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<int> arr;
vector<long long> combi;
long long ret;
void cal(int sIdx, int depth, long long stackNum) {
  if (depth == K) {
    if (stackNum > ret) {
      ret = stackNum;
    }
    return;
  }
  if (combi[sIdx] & stackNum < ret) return;
  cal(sIdx + 1, depth + 1, stackNum + arr[sIdx]);
}
int main() {
  scanf("%d %d", &N, &K);
  arr.resize(N);
  long long maxNum = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &arr[i]);
    maxNum += arr[i];
  }
  ret = 99999999999999ll;
  sort(arr.begin(), arr.end());
  int numOfChoose = 1;
  for (int i = 1; i <= N; ++i) {
    for (int idx = 0; idx < N - i; ++idx) {
      long long sum = 0ll;
      for (int s = idx; s < idx + i; ++s) {
        sum += arr[idx];
      }
      combi.push_back(sum);
    }
  }
  for (int i = 0; i < combi.size(); ++i) {
    cal(i, 0, 0);
  }
  printf("%lld\n", ret);
  return 0;
}
