import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Hindenburg {
    public static int mask;
    public static void main(String[] args) throws IOException {
        var sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        var list = new LinkedList<Integer>();

        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }

        Collections.sort(list, Comparator.reverseOrder());

        for (int i = 30; i > 0 ; i--) {
            mask = 1 << i;

            long count = list.stream().filter(x -> (x & mask) != 0).count();
            if (count >= k) {
                list.removeIf(x -> (x & mask) == 0);
            }
        }

        int count = 0;
        int result = list.get(0);

        for (int x : list) {
            result &= x;

            count++;
            if (count >= k) {
                break;
            }
        }

        System.out.println(result);
    }
}

