import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class B {
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		int t = s.nextInt();
		while (t-- > 0) {
			int n = s.nextInt();
			int k = s.nextInt();
			String str = s.nextLine();
			char[] arr = str.toCharArray();
			int[] freq = new int[26];
			for (int i = 0; i < n; i++) {
				freq[arr[i] - 'a']++;
			}
			int flag = 0;
			ArrayList<pair> list = new ArrayList<>();
			for (int i = 0; i < 26; i++) {
				if (freq[i] > 0) {
					pair temp = new pair(i, freq[i]);
					list.add(temp);
				}
			}
			if (list.size() == 1) {
				StringBuilder ans = new StringBuilder();
				for (int i = 0; i < list.get(0).y / k; i++) {
					ans.append((char) (list.get(0).x + 'a'));
				}
				if (list.get(0).y % k > 0)
					ans.append((char) (list.get(0).x + 'a'));
				p.println(ans.toString());
				continue;
			}
			int mini = 0;
			for (int i = 0; i < list.size(); i++) {
				pair temp = list.get(i);
				if (temp.y % k == 0)
					continue;
				else {
					flag = 1;
					mini = i;
					break;
				}
			}
			if (flag == 0) {
				StringBuilder ans = new StringBuilder();
				for (int i = 0; i < list.size(); i++) {
					pair temp = list.get(i);
					int val = list.get(i).y / k;
					char ch = (char) (temp.x + 'a');

					for (int j = 0; j < val; j++) {
						ans.append(ch);
					}
				}
				p.println(ans.toString());
				continue;
			}
			if (mini == 0) {
				if (list.get(0).y < k) {
					p.println((char) (list.get(1).x + 'a'));
					continue;
				} else {
					StringBuilder ans = new StringBuilder();
					for (int i = 0; i < list.get(0).y - k - 1; i++) {
						ans.append((char) (list.get(0).x + 'a'));
					}
					for (int i = 1; i < list.size(); i++) {
						pair temp = list.get(i);
						int val = list.get(i).y;
						char ch = (char) (temp.x + 'a');

						for (int j = 0; j < val; j++) {
							ans.append(ch);
						}
					}
					p.println(ans);
					continue;
				}
			}
			StringBuilder ans = new StringBuilder();
			ans.append((char) (list.get(0).x + 'a'));
			for (int i = 1; i < list.size(); i++) {
				pair temp = list.get(i);
				int val = list.get(i).y;
				char ch = (char) (temp.x + 'a');

				for (int j = 0; j < val; j++) {
					ans.append(ch);
				}
			}
			p.println(ans.toString());
		}
		p.flush();
		p.close();
	}

	public static long GCD(long a, long b) {
		if (a == 0)
			return b;
		return GCD(b % a, a);
	}

	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}

	static class pair implements Comparable<pair> {
		Integer x, y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if (result == 0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x - x == 0 && p.y - y == 0;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}

		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}

		}

		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;

			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];

				else if (q > end)
					Arr[(int) k++] = A[(int) p++];

				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];

				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}

		}

	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class B {
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		int t = s.nextInt();
		while (t-- > 0) {
			int n = s.nextInt();
			int k = s.nextInt();
			String str = s.nextLine();
			char[] arr = str.toCharArray();
			int[] freq = new int[26];
			for (int i = 0; i < n; i++) {
				freq[arr[i] - 'a']++;
			}
			int flag = 0;
			ArrayList<pair> list = new ArrayList<>();
			for (int i = 0; i < 26; i++) {
				if (freq[i] > 0) {
					pair temp = new pair(i, freq[i]);
					list.add(temp);
				}
			}
			if (list.size() == 1) {
				StringBuilder ans = new StringBuilder();
				for (int i = 0; i < list.get(0).y / k; i++) {
					ans.append((char) (list.get(0).x + 'a'));
				}
				if (list.get(0).y % k > 0)
					ans.append((char) (list.get(0).x + 'a'));
				p.println(ans.toString());
				continue;
			}
			if (list.size() == 2 && list.get(0).y == k) {
				StringBuilder ans = new StringBuilder();
				ans.append((char) (list.get(0).x + 'a'));
				char ch = (char) (list.get(1).x + 'a');
				for (int i = 0; i < list.get(1).y / k; i++) {
					ans.append(ch);
				}
				if (list.get(1).y % k != 0)
					ans.append(ch);
				p.println(ans.toString());
				continue;
			}
			StringBuilder ans = new StringBuilder();
			if (list.get(0).y < k) {
				p.println((char) (list.get(1).x + 'a'));
				continue;
			}
			list.get(0).y -= k;
			ans.append((char) (list.get(0).x + 'a'));
			for (int i = 0; i < list.size(); i++) {
				char ch = (char) (list.get(i).x + 'a');
				for (int j = 0; j < list.get(i).y; j++)
					ans.append(ch);
			}
			p.println(ans.toString());

		}
		p.flush();
		p.close();
	}

	public static long GCD(long a, long b) {
		if (a == 0)
			return b;
		return GCD(b % a, a);
	}

	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}

	static class pair implements Comparable<pair> {
		Integer x, y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if (result == 0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x - x == 0 && p.y - y == 0;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}

		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}

		}

		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;

			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];

				else if (q > end)
					Arr[(int) k++] = A[(int) p++];

				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];

				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}

		}

	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;

public class B {
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		int t = s.nextInt();
		while (t-- > 0) {
			int n = s.nextInt();
			int k = s.nextInt();
			String str = s.nextLine();
			char[] arr = str.toCharArray();
			ArrayList<Character> sorted = new ArrayList<>();
			StringBuilder temp = new StringBuilder();

			for (int i = 0; i < arr.length; i++) {
				sorted.add(arr[i]);
			}
			Collections.sort(sorted);
			for (int i = 0; i < n; i++)
				temp.append(sorted.get(i));
			if (k == 1) {
				p.println(temp.toString());
				continue;
			}
			StringBuilder ans = new StringBuilder();
			ans.append(sorted.get(k - 1));
			if (n == k || sorted.get(k - 1) > sorted.get(0)) {
				p.println(ans);
				continue;
			}
			if (sorted.get(k) == sorted.get(sorted.size() - 1)) {
				int i = k;
				while (n - i >= k && i < n) {
					ans.append(sorted.get(i));
					i += k;
				}
				if (i < n) {
					ans.append(sorted.get(n - 1));
				}
			} else {
				ans.append(temp.toString().substring(k));
			}
			p.println(ans);
		}
		p.flush();
		p.close();
	}

	public static long GCD(long a, long b) {
		if (a == 0)
			return b;
		return GCD(b % a, a);
	}

	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}

	static class pair implements Comparable<pair> {
		Integer x, y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if (result == 0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x - x == 0 && p.y - y == 0;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}

		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}

		}

		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;

			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];

				else if (q > end)
					Arr[(int) k++] = A[(int) p++];

				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];

				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}

		}

	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class B {
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		int t = s.nextInt();
		while (t-- > 0) {
			int n = s.nextInt();
			int k = s.nextInt();
			String str = s.nextLine();
			char[] arr = str.toCharArray();
			int[] freq = new int[26];
			for (int i = 0; i < n; i++) {
				freq[arr[i] - 'a']++;
			}
			int flag = 0;
			ArrayList<pair> list = new ArrayList<>();
			for (int i = 0; i < 26; i++) {
				if (freq[i] > 0) {
					pair temp = new pair(i, freq[i]);
					list.add(temp);
				}
			}
			if (list.size() == 1) {
				StringBuilder ans = new StringBuilder();
				for (int i = 0; i < list.get(0).y / k; i++) {
					ans.append((char) (list.get(0).x + 'a'));
				}
				if (list.get(0).y % k > 0)
					ans.append((char) (list.get(0).x + 'a'));
				p.println(ans.toString());
				continue;
			}
			if (list.size() == 2) {
				int flag2 = 0;
				StringBuilder ans = new StringBuilder();
				if (list.get(0).y == k) {
					ans.append((char) (list.get(0).x + 'a'));
				} else {
					flag2 = 1;
				}
				if (flag2 == 0) {
					for (int i = 0; i < list.get(1).y / k; i++) {
						ans.append((char) (list.get(1).x + 'a'));
					}
					if (list.get(1).y % k != 0) {
						ans.append((char) (list.get(1).x + 'a'));
					}
					p.println(ans);
					continue;
				}
			}
			int mini = 0;
			for (int i = 0; i < list.size(); i++) {
				pair temp = list.get(i);
				if (temp.y % k == 0)
					continue;
				else {
					flag = 1;
					mini = i;
					break;
				}
			}
			if (mini == 0) {
				if (list.get(0).y < k) {
					p.println((char) (list.get(1).x + 'a'));
					continue;
				} else {
					StringBuilder ans = new StringBuilder();
					for (int i = 0; i < list.get(0).y - (k - 1); i++) {
						ans.append((char) (list.get(0).x + 'a'));
					}
					for (int i = 1; i < list.size(); i++) {
						pair temp = list.get(i);
						int val = list.get(i).y;
						char ch = (char) (temp.x + 'a');
						for (int j = 0; j < val; j++) {
							ans.append(ch);
						}
					}
					p.println(ans);
					continue;
				}
			}
			StringBuilder ans = new StringBuilder();
			for (int i = 0; i < list.get(0).y - (k - 1); i++) {
				ans.append((char) (list.get(0).x + 'a'));
			}
			for (int i = 1; i < list.size(); i++) {
				pair temp = list.get(i);
				int val = list.get(i).y;
				char ch = (char) (temp.x + 'a');

				for (int j = 0; j < val; j++) {
					ans.append(ch);
				}
			}
			p.println(ans.toString());
		}
		p.flush();
		p.close();
	}

	public static long GCD(long a, long b) {
		if (a == 0)
			return b;
		return GCD(b % a, a);
	}

	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}

	static class pair implements Comparable<pair> {
		Integer x, y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if (result == 0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x - x == 0 && p.y - y == 0;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}

		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}

		}

		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;

			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];

				else if (q > end)
					Arr[(int) k++] = A[(int) p++];

				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];

				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}

		}

	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class B {
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		int t = s.nextInt();
		while (t-- > 0) {
			int n = s.nextInt();
			int k = s.nextInt();
			String str = s.nextLine();
			char[] arr = str.toCharArray();
			int[] freq = new int[26];
			for (int i = 0; i < n; i++) {
				freq[arr[i] - 'a']++;
			}
			int flag = 0;
			ArrayList<pair> list = new ArrayList<>();
			for (int i = 0; i < 26; i++) {
				if (freq[i] > 0) {
					pair temp = new pair(i, freq[i]);
					list.add(temp);
				}
			}
			if (list.size() == 1) {
				StringBuilder ans = new StringBuilder();
				for (int i = 0; i < list.get(0).y / k; i++) {
					ans.append((char) (list.get(0).x + 'a'));
				}
				if (list.get(0).y % k > 0)
					ans.append((char) (list.get(0).x + 'a'));
				p.println(ans.toString());
				continue;
			}
			int mini = 0;
			for (int i = 0; i < list.size(); i++) {
				pair temp = list.get(i);
				if (temp.y % k == 0)
					continue;
				else {
					flag = 1;
					mini = i;
					break;
				}
			}
			if (mini == 0) {
				if (list.get(0).y < k) {
					p.println((char) (list.get(1).x + 'a'));
					continue;
				} else {
					StringBuilder ans = new StringBuilder();
					for (int i = 0; i < list.get(0).y - (k - 1); i++) {
						ans.append((char) (list.get(0).x + 'a'));
					}
					for (int i = 1; i < list.size(); i++) {
						pair temp = list.get(i);
						int val = list.get(i).y;
						char ch = (char) (temp.x + 'a');
						for (int j = 0; j < val; j++) {
							ans.append(ch);
						}
					}
					p.println(ans);
					continue;
				}
			}
			StringBuilder ans = new StringBuilder();
			for (int i = 0; i < list.get(0).y - (k - 1); i++) {
				ans.append((char) (list.get(0).x + 'a'));
			}
			for (int i = 1; i < list.size(); i++) {
				pair temp = list.get(i);
				int val = list.get(i).y;
				char ch = (char) (temp.x + 'a');

				for (int j = 0; j < val; j++) {
					ans.append(ch);
				}
			}
			p.println(ans.toString());
		}
		p.flush();
		p.close();
	}

	public static long GCD(long a, long b) {
		if (a == 0)
			return b;
		return GCD(b % a, a);
	}

	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}

	static class pair implements Comparable<pair> {
		Integer x, y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if (result == 0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x - x == 0 && p.y - y == 0;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}

		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}

		}

		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;

			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];

				else if (q > end)
					Arr[(int) k++] = A[(int) p++];

				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];

				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}

		}

	}

}


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

public class Solution
{
   public static String ans(ArrayList<Character> s,int n,int k,String str){
     if(s.get(0)!=s.get(k-1))
     return s.get(k-1)+"";
     boolean all_same=true;
     for(int i=k;i<n-1;i++){
         if(s.get(i)!=s.get(i+1))
         {
             all_same=false;
             break;
         }
     }
     if(all_same==false){
         String ans=s.get(0)+"";
         for(int i=k;i<n;i++)
         ans=ans+s.get(i);
         return ans;
     }
     String ans[]=new String[k];
     for(int i=0;i<k;i++)
     ans[i]="";
     for(int i=0;i<n;i++){
         ans[i%k]=ans[i%k]+s.get(i);
     }
     Arrays.sort(ans);
     return ans[k-1];
   }

    public static void main(String[] args) throws IOException
    {

       BufferedReader br = new BufferedReader(
                              new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=0;i<t;i++){
         StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int k=Integer.parseInt(st.nextToken());
        String str=br.readLine();
        ArrayList<Character> s=new ArrayList<>();
        for(int j=0;j<n;j++){
            s.add(str.charAt(j));
        }
        Collections.sort(s);
        System.out.println(ans(s,n,k,str));
        }

}}


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

public class Solution
{
   public static String ans(ArrayList<Character> s,int n,int k,String str){
     if(s.get(0)!=s.get(k-1))
     return s.get(k-1)+"";
     boolean all_same=true;
     for(int i=k;i<n-1;i++){
         if(s.get(i)!=s.get(i+1))
         {
             all_same=false;
             break;
         }
     }
     if(all_same==false){
         String ans=s.get(0)+"";
         for(int i=k;i<n;i++)
         ans=ans+s.get(i);
         return ans;
     }

    String ans=s.get(0)+"";
    int num=n-k;
    char ch=s.get(k);
    for(int i=0;i<(num/k);i++)
    ans=ans+ch;
    if(num%k!=0)
    ans=ans+ch;
    return ans;
   }

    public static void main(String[] args) throws IOException
    {

       BufferedReader br = new BufferedReader(
                              new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=0;i<t;i++){
         StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int k=Integer.parseInt(st.nextToken());
        String str=br.readLine();
        ArrayList<Character> s=new ArrayList<>();
        for(int j=0;j<n;j++){
            s.add(str.charAt(j));
        }
        Collections.sort(s);
        System.out.println(ans(s,n,k,str));
        }

}}


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

public class Solution
{
   public static String ans(char[] s,int n,int k,String str){
     if(s[0]!=s[k-1])
     return s[k-1]+"";
     boolean all_same=true;
     for(int i=k;i<n-1;i++){
         if(s[i]!=s[i+1])
         {
             all_same=false;
             break;
         }
     }
     if(all_same==false){
         String ans=s[0]+"";
         for(int i=k;i<n;i++)
         ans=ans+s[i];
         return ans;
     }
     String ans[]=new String[k];
     for(int i=0;i<k;i++)
     ans[i]="";
     for(int i=0;i<n;i++){
         ans[i%k]=ans[i%k]+s[i];
     }
     Arrays.sort(ans);
     return ans[k-1];
   }

    public static void main(String[] args) throws IOException
    {

       BufferedReader br = new BufferedReader(
                              new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=0;i<t;i++){
         StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int k=Integer.parseInt(st.nextToken());
        String str=br.readLine();
        char s[]=new char[n];
        for(int j=0;j<n;j++){
            s[j]=str.charAt(j);
        }
        Arrays.sort(s);
        System.out.println(ans(s,n,k,str));
        }

}}


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

public class Solution
{
   public static String ans(ArrayList<Character> s,int n,int k,String str){
     if(s.get(0)!=s.get(k-1))
     return s.get(k-1)+"";
     boolean all_same=true;
     for(int i=k;i<n-1;i++){
         if(s.get(i)!=s.get(i+1))
         {
             all_same=false;
             break;
         }
     }
     if(all_same==false){
         String ans=s.get(0)+"";
         for(int i=k;i<n;i++)
         ans=ans+s.get(i);
         return ans;
     }

    String ans=s.get(0)+"";
    int num=n-k;
    char ch;
    if(k<n){
    ch=s.get(k);
    for(int i=0;i<(num/k);i++)
    ans=ans+ch;
    if(num%k!=0)
    ans=ans+ch;
    }
    return ans;
   }

    public static void main(String[] args) throws IOException
    {

       BufferedReader br = new BufferedReader(
                              new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=0;i<t;i++){
         StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int k=Integer.parseInt(st.nextToken());
        String str=br.readLine();
        ArrayList<Character> s=new ArrayList<>();
        for(int j=0;j<n;j++){
            s.add(str.charAt(j));
        }
        Collections.sort(s);
        System.out.println(ans(s,n,k,str));
        }

}}


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

public class Solution
{
   public static String ans(ArrayList<Character> s,int n,int k,String str){
     if(s.get(0)!=s.get(k-1))
     return s.get(k-1)+"";
     boolean all_same=true;
     for(int i=k;i<n-1;i++){
         if(s.get(i)!=s.get(i+1))
         {
             all_same=false;
             break;
         }
     }
     if(all_same==false){
         String ans=s.get(0)+"";
         for(int i=k;i<n;i++)
         ans=ans+s.get(i);
         return ans;
     }

    String ans=s.get(0)+"";
    int num=n-k;
    char ch;
    if(k<n){
    ch=s.get(k);
    for(int i=0;i<(num/k);i++)
    ans=ans+ch;
    if(num%k!=0)
    ans=ans+ch;
    }
    return ans;
   }

    public static void main(String[] args) throws IOException
    {

       BufferedReader br = new BufferedReader(
                              new InputStreamReader(System.in));
                                StringBuilder out = new StringBuilder();
        int t=Integer.parseInt(br.readLine());
        for(int q=0;q<t;q++){
         StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int k=Integer.parseInt(st.nextToken());
        String str=br.readLine();
        ArrayList<Character> s=new ArrayList<>();
        for(int j=0;j<n;j++){
            s.add(str.charAt(j));
        }
        Collections.sort(s);
        // System.out.println(ans(s,n,k,str));

         if(s.get(0)!=s.get(k-1)){
    out.append(s.get(k-1)+"");
    out.append("\n");
    continue;
         }
     boolean all_same=true;
     for(int i=k;i<n-1;i++){
         if(s.get(i)!=s.get(i+1))
         {
             all_same=false;
             break;
         }
     }
     if(all_same==false){
         out.append(s.get(k-1)+"");
         for(int i=k;i<n;i++)
         out.append(s.get(i));
          out.append("\n");
    continue;
     }

    out.append(s.get(k-1)+"");

    int num=n-k;
    char ch;
    if(k<n){
    ch=s.get(k);
    for(int i=0;i<(num/k);i++)
    out.append(ch);
    if(num%k!=0)
    out.append(ch);
    }
    out.append("\n");

        }
        System.out.println(out);

}}


#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long

using namespace std;
const int maxn=1e5+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm];
int fuck(int xx, int x)
{
    // printf("%d, %d\n", xx, x);
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    else if(xx>=x&&xx<x*2) return dep[xx]=1;
    else return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(int x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<=maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){
        int l=0, r=0, mid;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            r=max(r, a[i]);
        }
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        for(int i=0; i<10; i++)printf("%d ", dep[i]);
        if(l>0)printf("%d\n", l);
        else printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int T, n, m, Max, l, r, mid, a[1000001];
int Calc(int x, int y)
{
    if (x < y)
        return 0;
    if (y == 1)
        return x;
    int t, tmp, temp;
    for (t = 1; (t << 1) <= x / y; t <<= 1);
    for (tmp = x, temp = 1; (tmp >> 1) + 1 >= y; tmp >>= 1, temp <<= 1);
    return max(t, x - tmp * temp);
}
bool Judge(int x)
{
    long long s = 0;
    for (int i = 1; i <= n; i++)
        s += (long long)Calc(a[i], x);
    return s >= (long long)m;
}
int main()
{
    while (~scanf("%d%d", &n, &m))
    {

        Max = 0;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &a[i]);
            Max = max(Max, a[i]);
        }
        l = 0;
        r = Max + 1;
        while (r - l > 1)
        {
            mid = l + r >> 1;
            Judge(mid) ? l = mid : r = mid;
        }
        printf("%d\n", l ? l : -1);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long

using namespace std;
const int maxn=1e5+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm];
int fuck(int xx, int x)
{
    // printf("%d, %d\n", xx, x);
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    else if(xx>=x&&xx<x*2) return dep[xx]=1;
    else return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(int x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<=maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){
        int l=0, r=0, mid;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            r=max(r, a[i]);
        }
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        //for(int i=0; i<10; i++)printf("%d ", dep[i]);
        if(l>0)printf("%d\n", l);
        else printf("-1\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long

using namespace std;
const int maxn=1e5+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm];
int fuck(int xx, int x)
{
    // printf("%d, %d\n", xx, x);
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    else if(xx>=x&&xx<x*2) return dep[xx]=1;
    else return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(int x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<=maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m);){
        int l=0, r=0, mid;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            r=max(r, a[i]);
        }
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        for(int i=0; i<10; i++)printf("%d ", dep[i]);
        if(l>0)printf("%d\n", l);
        else printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int T, n, m, Max, l, r, mid, a[100001];
int Calc(int x, int y)
{
    if (x < y)
        return 0;
    if (y == 1)
        return x;
    int t, tmp, temp;
    for (t = 1; (t << 1) <= x / y; t <<= 1);
    for (tmp = x, temp = 1; (tmp >> 1) + 1 >= y; tmp >>= 1, temp <<= 1);
    return max(t, x - tmp * temp);
}
bool Judge(int x)
{
    long long s = 0;
    for (int i = 1; i <= n; i++)
        s += (long long)Calc(a[i], x);
    return s >= (long long)m;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // scanf("%d", &T);
    while (~scanf("%d%d", &n, &m))
    {

        Max = 0;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &a[i]);
            Max = max(Max, a[i]);
        }
        l = 0;
        r = Max + 1;
        while (r - l > 1)
        {
            mid = l + r >> 1;
            Judge(mid) ? l = mid : r = mid;
        }
        printf("%d\n", l ? l : -1);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;
const int maxn=1e6+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm];

int fuck(int xx, ll x)
{
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    if(xx>=x&&xx<x*2) return dep[xx]=1;
    return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(ll x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){
        ll l=0, r=0, mid;
        ll summ=0;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            summ+=a[i];
        }
        if(summ<m){printf("-1\n");continue;}
        r=summ;
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        printf("%d\n", l);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int m,n;
int a[100005];
int dpa[1000000];
long long ans;

long long dp(long long x)
{
    if(x<1000000&&dpa[x]!=-1) return dpa[x];
    if(x<ans&&x<1000000) return dpa[x]=0;
    if(x/2<ans&&x<1000000) return dpa[x]=1;
    return x<1000000?dpa[x]=dp(x/2)+dp(x-x/2):dp(x/2)+dp(x-x/2);
}

bool f(int x)
{
    long long ans=0;
    memset(dpa,-1,sizeof dpa);
    for(int i=0;i<n;i++)
        ans+=dp(a[i]);
    return ans>=m;
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    int i,j,k,t;
    long long l,r;
    // scanf("%d",&t);
    while(~scanf("%d%d",&n,&m))
    {

        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        ans=0;
        for(i=0;i<n;i++)
            ans+=a[i];
        if(ans<m)
        {
            printf("-1\n");
            continue;
        }
        l=1;
        r=ans;
        while(r>l+1)
        {
            ans=(l+r)/2;
            if(f(ans)) l=ans;
            else r=ans;
        }
        if(f(ans=r)) l=r;
        ans=l;
        printf("%I64d\n",ans);
    }
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long

using namespace std;
const int maxn=1e6+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm], maxx;
bool check(ll x)
{
    ll res=0;
    if(x==0) return 1;
    memset(dep, 0, sizeof(dep));
    for(int i=x; i<=maxx; i++){
        dep[i]=dep[i/2]+dep[(i+1)/2];
        dep[i]=max(dep[i], 1);
    }
    for(int i=0; i<n; i++){
        res+=dep[a[i]];
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){

        int l=0, r=0, mid;
        ll summ=0;
        maxx=0;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            summ+=a[i];
            maxx=max(maxx, a[i]);
        }
        r=maxx;
        if(summ<m){printf("-1\n");continue;}
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        printf("%d\n", l);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;
const int maxn=1e5+5;
const int maxm=1e5+5;
int a[maxn], n, m, dep[maxm];

int fuck(int xx, int x)
{
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    else if(xx>=x&&xx<x*2) return dep[xx]=1;
    else return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(int x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){
        int l=0, r=0, mid;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            r=max(r, a[i]);
        }
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        if(l>0)printf("%d\n", l);
        else printf("-1\n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[10000007], a[1000005];
int main(void)
{
    int i, n, k, A, l, r, m;
    long long cnt;
    scanf("%d%d", &n, &k);
    for(i=1;i<=n;i++)
        scanf("%d", &a[i]);
    A = *max_element(a+1, a+n+1);
    l = -1, r = A;
    while(l<r)
    {
        m = (l+r+1)/2;
        memset(dp, 0, sizeof(dp));
        for(i=m;i<=A;i++)
        {
            dp[i] = dp[i/2]+dp[(i+1)/2];
            dp[i] = max(dp[i], 1);
        }
        cnt = 0;
        for(i=1;i<=n;i++)
            cnt += dp[a[i]];
        if(cnt>=k)
            l = m;
        else
            r = m-1;
    }
    printf("%d\n", l);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long

using namespace std;
const int maxn=1e5+5;
const int maxm=1e5+5;
int a[maxn], n, m, dep[maxm];
int fuck(int xx, int x)
{
    // printf("%d, %d\n", xx, x);
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    else if(xx>=x&&xx<x*2) return dep[xx]=1;
    else return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(int x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<=maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){
        int l=0, r=0, mid;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            r=max(r, a[i]);
        }
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        if(l>0)printf("%d\n", l);
        else printf("-1\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;
const int maxn=1e5+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm];

int fuck(int xx, int x)
{
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    else if(xx>=x&&xx<x*2) return dep[xx]=1;
    else return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(int x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){
        int l=0, r=0, mid;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            r=max(r, a[i]);
        }
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        if(l>0)printf("%d\n", l);
        else printf("-1\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long

using namespace std;
const int maxn=1e5+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm];
int fuck(int xx, int x)
{
    // printf("%d, %d\n", xx, x);
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    else if(xx>=x&&xx<x*2) return dep[xx]=1;
    else return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(int x)
{
    ll res=0;
    //if(x==0) return 1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m);){
        int l=0, r=0, mid;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            r=max(r, a[i]);
        }
        while(l<r){
            mid=(l+r+1)/2;
            for(int i=0; i<=maxm; i++)dep[i]=-1;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        for(int i=0; i<10; i++)printf("%d ", dep[i]);
        if(l>0)printf("%d\n", l);
        else printf("-1\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;
const int maxn=1e6+5;
const int maxm=1e7+5;
int a[maxn], n, m, dep[maxm];

int fuck(int xx, ll x)
{
    if(dep[xx]!=-1)return dep[xx];
    if(xx<x)return dep[xx]=0;
    if(xx>=x&&xx<x*2) return dep[xx]=1;
    return dep[xx]=fuck(xx/2, x)+fuck((xx+1)/2, x);
}
bool check(ll x)
{
    ll res=0;
    if(x==0) return 1;
    for(int i=0; i<maxm; i++)dep[i]=-1;
    for(int i=0; i<n; i++){
        res+=fuck(a[i], x);
    }
    if(res>=m)return 1;
    else return 0;
}
int main()
{
    #ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    // int t;
    // scanf("%d", &t);
    while(~scanf("%d %d", &n, &m)){
        ll l=0, r=0, mid;
        ll summ=0;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
            summ+=a[i];
        }
        if(summ<m)printf("-1\n");
        r=summ;
        while(l<r){
            mid=(l+r+1)/2;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        printf("%d\n", l);
    }
    return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],s,q;
bool ok=1;
bool cty(int m){
     int o=0;
     for(int i=1;i<=n;i++)o+=a[i]/m;
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
            scanf("%d",a+i);
            if(a[i]==1)ok=0;
            s+=a[i];
    }
    if(s<k)ok=0;
    if(!ok){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
	//system("pause");
	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],f[10000005],s;
bool cty(int m){
     if(m==1) return s;
     int o=0;
     for(int i=1;i<=n;i++)o+=f[a[i]/m];
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    int q=1;
    for(int i=1;i<=10000000;i++){
            if(i==q)f[i]=i,q=q*2;
            else f[i]=f[i-1];
    }
    for(int i=1;i<=n;i++){
            scanf("%d",a+i);
            s+=a[i];
    }
    if(!cty(1)){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
//	system("pause");
	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],f[10000005],s;
bool cty(int m){
     if(m==1) return s>=k;
     int o=0;
     for(int i=1;i<=n;i++)o+=f[a[i]/m];
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    int q=1;
    for(int i=1;i<=10000000;i++){
            if(i==q)f[i]=i,q=q*2;
            else f[i]=f[i-1];
    }
    for(int i=1;i<=n;i++){
            scanf("%d",a+i);
            s+=a[i];
    }
    if(!cty(1)){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
//	system("pause");
	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],f[10000005];
long long s;
bool cty(int m){
     if(m==1) return s>=k;
     long long o=0;
     for(int i=1;i<=10000000;i++){
             f[i]=(i>=m);
             f[i]=max(f[i],f[i>>1]+f[(i+1)>>1]);
     }
     for(int i=1;i<=n;i++)o+=f[a[i]];
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
            scanf("%d",a+i);
            s+=1ll*a[i];
    }
    if(!cty(1)){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
//	system("pause");
	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],f[10000005];
long long s;
bool cty(int m){
     if(m==1) return s>=k;
     long long o=0;
     for(int i=1;i<=n;i++)o+=1ll*f[a[i]/m];
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    int q=1;
    for(int i=1;i<=10000000;i++){
            if(i==q)f[i]=i,q=q*2;
            else f[i]=f[i-1];
    }
    for(int i=1;i<=n;i++){
            scanf("%d",a+i);
            s+=1ll*a[i];
    }
    if(!cty(1)){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
	//system("pause");
	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],f[10000005];
bool cty(int m){
     int o=0;
     for(int i=1;i<=n;i++)o+=f[a[i]/m];
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    int q=1;
    for(int i=1;i<=10000000;i++){
            if(i==q)f[i]=i,q=q*2;
            else f[i]=f[i-1];
    }
    for(int i=1;i<=n;i++){
            scanf("%d",a+i);
    }
    if(!cty(1)){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
//	system("pause");
	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],f[10000005],s;
bool cty(int m){
     if(m==1) return s>=k;
     long long o=0;
     for(int i=1;i<=n;i++)o+=1ll*f[a[i]/m];
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    int q=1;
    for(int i=1;i<=10000000;i++){
            if(i==q)f[i]=i,q=q*2;
            else f[i]=f[i-1];
    }
    for(int i=1;i<=n;i++){
            scanf("%d",a+i);
            s+=a[i];
    }
    if(!cty(1)){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
//	system("pause");
	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,k,a[1000005],s;
bool cty(int m){
     int o=0;
     for(int i=1;i<=n;i++)o+=a[i]/m;
     return o>=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",a+i),s+=a[i];
    if(s<k){
            printf("-1\n");
            return 0;
    }
    int l=1,r=10000000;
    while(r-l>1){
                 int m=(l+r)/2;
                 if(cty(m))l=m;
                 else r=m;
    }
    while(!cty(l))l--;
    while(cty(l+1))l++;
    printf("%d\n",l);
//	system("pause");
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
     //freopen("in.txt","r",stdin);
     //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
               // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{   if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return vis[nc] = 0;
    if(nc == mid)
        return vis[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return vis[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
     //freopen("in.txt","r",stdin);
     //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
               // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{   if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return 0;
    if(nc == mid)
        return 1;
    if(nc/2<mid&&nc>=mid)
        return 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
int  dfs(int nc,int mid);
LL n,m;
using namespace std;
int  ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
           LL  l = 1;
            LL r = 2*1e9;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
            vis[mid] = t;
            ac[mid] = 1;
        }
        else if(plice[i] > mid)
        {
            cn+=(LL)dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
int  dfs(int nc,int mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return ac[nc] = 0;
    if(nc == mid)
        return ac[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return ac[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}
//


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
            vis[mid] = t;
            ac[mid] = 1;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return vis[nc] = 0;
    if(nc == mid)
        return vis[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return vis[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
     //freopen("in.txt","r",stdin);
     //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
               // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{   if(t == vis[nc]){vis[nc] = t;return ac[nc];}

    if(nc < mid)return 0;
    if(nc == mid)
        return 1;
    if(nc/2<mid&&nc>=mid)
        return 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
            vis[mid] = t;
            ac[mid] = 1;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return vis[nc] = 0;
    if(nc == mid)
        return vis[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return vis[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}
//


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
int main(void)
{
     //freopen("in.txt","r",stdin);
     //freopen("out.txt","w",stdout);
    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(nc < mid)return 0;
    if(nc == mid)
        return 1;
    if(nc/2<mid&&nc>=mid)
        return 1;
    if(nc%2)
    {
        return dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[100];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] < mid)
        {
          continue;
        }
        else if(plice[i] >= mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return ac[nc] = 0;
    if(nc == mid)
        return ac[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return ac[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
int plice[1000005];
bool check(LL mid);
int  dfs(int nc,int mid);
LL n,m;
using namespace std;
int  ac[10000001];
int t = 0;
int vis[10000001];
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,BufferSize,stdin);
        tail=(head=buffer)+l;
    }
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 1;LL maxx = 0;
        for(int i = 0; i < n; i++)
        {
            plice[i] = read();
            sum += plice[i];
            maxx = max((LL)plice[i],maxx);
        }
        if(sum < m)printf("-1\n");
        else
        {   sort(plice,plice+n);
            LL  l = 1;
            LL r = maxx;
            LL id = -1;
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
            vis[mid] = t;
            ac[mid] = 1;
        }
        else if(plice[i] > mid)
        {
            cn+=(LL)dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
int  dfs(int nc,int mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return ac[nc] = 0;
    if(nc%2)
    {   if(nc/2 < mid)return ac[nc] = 1;

        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    else
    {if(nc/2 < mid) return ac[nc] = 1;
    return ac[nc] = (LL)2*dfs(nc/2,mid);}
}
//


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
map<LL,LL>my;
int main(void)
{
     //freopen("in.txt","r",stdin);
     //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            while(l <= r)
            {   my.clear();
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
               // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(nc < mid)return 0;
    if(nc == mid)
        return 1;
    if(nc/2<mid&&nc>=mid)
        return 1;
    if(nc%2)
    {
        return my[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return my[nc] = (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
int  dfs(int nc,int mid);
LL n,m;
using namespace std;
int  ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 1;LL maxx = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
            maxx = max(plice[i],maxx);
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL  l = 1;
            LL r = maxx;
            LL id = -1;
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
            vis[mid] = t;
            ac[mid] = 1;
        }
        else if(plice[i] > mid)
        {
            cn+=(LL)dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
int  dfs(int nc,int mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return ac[nc] = 0;
    if(nc%2)
    {   if(nc/2 < mid)return ac[nc] = 1;

        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    else
    {if(nc/2 < mid) return ac[nc] = 1;
    return ac[nc] = (LL)2*dfs(nc/2,mid);}
}
//


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
int main(void)
{

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    int cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//printf("%d\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(nc < mid)return 0;
    if(nc == mid)
        return 1;
    if(nc%2)
    {
        return dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
int  dfs(int nc,int mid);
LL n,m;
using namespace std;
int  ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;LL maxx = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
            maxx = max(plice[i],maxx);
        }
        if(sum < m)printf("-1\n");
        else
        {
           LL  l = 1;
            LL r = maxx;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
            vis[mid] = t;
            ac[mid] = 1;
        }
        else if(plice[i] > mid)
        {
            cn+=(LL)dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
int  dfs(int nc,int mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return ac[nc] = 0;
    if(nc%2)
    {   if(nc/2 < mid)return ac[nc] = 1;

        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    else
    {if(nc/2 < mid) return ac[nc] = 1;
    return ac[nc] = (LL)2*dfs(nc/2,mid);}
}
//


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
int main(void)
{
     //freopen("in.txt","r",stdin);
     //freopen("out.txt","w",stdout);
    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
               // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(nc < mid)return 0;
    if(nc == mid)
        return 1;
    if(nc/2<mid&&nc>=mid)
        return 1;
    if(nc%2)
    {
        return dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] < mid)
        {
          continue;
        }
        else if(plice[i] >= mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return vis[nc] = 0;
    if(nc == mid)
        return vis[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return vis[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
            vis[mid] = t;
            ac[mid] = 1;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return ac[nc] = 0;
    if(nc == mid)
        return ac[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return ac[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}
//


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
int main(void)
{

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    int cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] == mid)
        {
            cn++;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//printf("%d\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(nc < mid)return 0;
    if(nc == mid)
        return 1;
    if(nc/2<mid&&nc>=mid)
        return 1;
    if(nc%2)
    {
        return dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return (LL)2*dfs(nc/2,mid);
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
typedef long long LL;
LL plice[1000005];
bool check(LL mid);
LL dfs(LL nc,LL mid);
LL n,m;
using namespace std;
LL ac[10000001];
int t = 0;
int vis[10000001];
int main(void)
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        LL sum = 0;
        t = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lld",&plice[i]);
            sum += plice[i];
        }
        if(sum < m)printf("-1\n");
        else
        {
            LL l = 1;
            LL r = 2*1e9;
            LL id = -1;
            memset(vis,-1,sizeof(vis));
            while(l <= r)
            {
                LL  mid = (l + r)/2;
                if(check(mid))
                    l = mid+1,id = mid;
                else r = mid-1;
                t++;
                // printf("%lld\n",mid);
            }
            printf("%lld\n",id);
        }
    }
    return 0;
}
bool check(LL mid)
{
    LL cn = 0;
    int i;//printf("%d\n",mid);
    for(i = 0; i < n; i++)
    {
        if(plice[i] < mid)
        {
          continue;
        }
        else if(plice[i] > mid)
        {
            cn+=dfs(plice[i],mid);
        }
    }//if(mid == 1)printf("%lld\n",cn);
    if(cn >= m)return true;
    else return false;
}
LL dfs(LL nc,LL mid)
{
    if(t == vis[nc])return ac[nc];
    vis[nc] = t;
    if(nc < mid)return vis[nc] = 0;
    if(nc == mid)
        return vis[nc]=1;
    if(nc/2<mid&&nc>=mid)
        return vis[nc] = 1;
    if(nc%2)
    {
        return ac[nc] = dfs(nc/2,mid)+dfs(nc/2+1,mid);
    }
    return ac[nc] = (LL)2*dfs(nc/2,mid);
}