import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int a = in.nextInt();
int b = in.nextInt();
int[] data=new int[a];
for(int i=0;i<a;i++){
data[i]=in.nextInt();
}
int res=subfunc(data,b);
System.out.println(res);
}
}
public static int subfunc(int[]data,int total){
int len=data.length;
int sum=0;
int max=Integer.MIN_VALUE;
int min=Integer.MAX_VALUE;
for(int i=0;i<len;i++){
max=Math.max(max,data[i]);
min=Math.min(min,data[i]);
sum+=data[i];
}
if(sum<=total){
return -1;
}
int temp=sum-total;
int cursum=0;
for(int i=max;i>=min;i--){
cursum=addsum(data,i);
if(cursum<=total){
return i;
}
}
return -1;
}
public static int addsum(int[] data,int top){
int sum=0;
for(int i=0;i<data.length;i++){
if(data[i]<=top){
sum+=data[i];
}
else{
sum+=top;
}
}
return sum;
}
}
int left=avrage;
int right=max;
int mid=0;
while(left<right){
mid=(left+right)/2;
int nowsum=addsum(data,mid);
if(nowsum<=total){
left=mid+1;
}
if(nowsum>total){
right=mid-1;
}
}
return mid;