using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k) = (c[0], c[1]); var a = NList; var initGroup = new Group(); initGroup.Same = true; for (var i = 0; i < n; ++i) initGroup.Group1.Add(i); var glist = new List{ initGroup }; var ans = 0; for (var i = 29; i >= 0; --i) { var nglist0 = new List(); var nglist1 = new List(); var zerocount = 0L; foreach (var g in glist) { if (g.Same) { var ng00 = new Group(); ng00.Same = true; var ng01 = new Group(); ng01.Same = true; var ng1 = new Group(); foreach (var idx in g.Group1) { if (((a[idx] >> i) & 1) == 0) { ng00.Group1.Add(idx); ng1.Group1.Add(idx); } else { ng01.Group1.Add(idx); ng1.Group2.Add(idx); } } if (ng00.Group1.Count > 1) { zerocount += (long)ng00.Group1.Count * (ng00.Group1.Count - 1) / 2; nglist0.Add(ng00); } if (ng01.Group1.Count > 1) { zerocount += (long)ng01.Group1.Count * (ng01.Group1.Count - 1) / 2; nglist0.Add(ng01); } if (ng1.Group1.Count > 0 && ng1.Group2.Count > 0) { nglist1.Add(ng1); } } else { var ng00 = new Group(); var ng01 = new Group(); var ng10 = new Group(); var ng11 = new Group(); foreach (var idx in g.Group1) { if (((a[idx] >> i) & 1) == 0) { ng00.Group1.Add(idx); ng10.Group1.Add(idx); } else { ng01.Group1.Add(idx); ng11.Group1.Add(idx); } } foreach (var idx in g.Group2) { if (((a[idx] >> i) & 1) == 0) { ng00.Group2.Add(idx); ng11.Group2.Add(idx); } else { ng01.Group2.Add(idx); ng10.Group2.Add(idx); } } if (ng00.Group1.Count > 0 && ng00.Group2.Count > 0) { zerocount += (long)ng00.Group1.Count * ng00.Group2.Count; nglist0.Add(ng00); } if (ng01.Group1.Count > 0 && ng01.Group2.Count > 0) { zerocount += (long)ng01.Group1.Count * ng01.Group2.Count; nglist0.Add(ng01); } if (ng10.Group1.Count > 0 && ng10.Group2.Count > 0) { nglist1.Add(ng10); } if (ng11.Group1.Count > 0 && ng11.Group2.Count > 0) { nglist1.Add(ng11); } } } if (zerocount >= k) { glist = nglist0; } else { glist = nglist1; k -= zerocount; ans += 1 << i; } } WriteLine(ans); } class Group { public bool Same; public List Group1 = new List(); public List Group2 = new List(); public override string ToString() { return $"f: {Same}\ng1: {string.Join(" ", Group1)}\ng2: {string.Join(" ", Group2)}"; } } }