import bisect n, m = map(int, input().rstrip().split()) k_pts = int(input()) pts_list = [] for i in range(n - 1): bisect.insort(pts_list, int(input())) def solve(k_pts, m, pts_list): for i in range(len(pts_list)): x = pts_list[i] del pts_list[i] counter = 0 for j in range(len(pts_list)): if counter > m: break elif len(pts_list) - j <= bisect.bisect_right(pts_list, k_pts + x - pts_list[- (j + 1)]): return x else: counter += 1 bisect.insort(pts_list, x) return -1 print(solve(k_pts, m, pts_list))