#include <bits/stdc++.h>
using namespace std;
int a[1000005];
bool cmp(int i1, int i2){
return i1 > i2;
}
int main(){
int n,M;
cin >> n >>M;
for (int i = 0;i < n;++i) cin >> a[i];
sort(a,a+n,cmp);
int l = 0,r = 1000000000;
while (l <= r){
int mid = l+(r-1)/2;
long long tot = 0;
for (int i = 0; i < n; i++){
if (a[i] > mid ) tot+= a[i] - mid;
else break;
}
if (tot > M) l = mid + 1;
else if (tot < M) r = mid - 1;
else {
cout << mid;
return 0;
}
}
cout << r;
return 0;
}