#include <iostream>

using namespace std;

const int NMAX = 50;

int v[NMAX], sp[NMAX][NMAX];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            sp[i][j] = sp[i][j - 1] | v[j];
        }
    }

    int ans = 0;
    for (int i = 1; i < (1 << n); i++) {
        if (i & 1) continue;

        int cnt = 0;
        for (int j = 1; j < n; j++) {
            if (i & (1 << j)) cnt++;
        }

        if (cnt != k - 1) continue;

        int ant = 1;
        int crt;
        int ix = 0;
        for (int j = 1; j < n; j++) {
            if (i & (1 << j)) {
                if (ix == 0) crt = sp[1][j], ix++;
                else crt = crt & sp[ant][j];

                ant = j + 1;
            }
        }

        crt = crt & sp[ant][n];

        ans = max(crt, ans);
    }

    cout << ans;
    return 0;
}
