#include <cstdio>
using namespace std;
int n,m,maxn,minn=0x7fffffff,ai[1000001],ans=0;
long long int now;
char Cget;
inline int max(int some1,int some2)
{
if(some1>some2) return some1;
else return some2;
}
inline int min(int some1,int some2)
{
if(some1<some2) return some1;
else return some2;
}
inline bool check(int now_)
{
now=0;
for(int i=1;i<=n;i++)
{
now+=max(0,ai[i]-now_);
}
if(now>=m)
{
ans=now_;
return true;
}
else return false;
}
inline void read_int(int &now_)
{
now_=0,Cget=getchar();
while(Cget>'9'||Cget<'0') Cget=getchar();
while(Cget<='9'&&Cget>='0')
{
now_=now_*10+Cget-'0';
Cget=getchar();
}
}
int main()
{
//scanf("%d%d",&n,&m);
read_int(n),read_int(m);
for(int i=1;i<=n;i++)
{
//scanf("%d",&ai[i]);
read_int(ai[i]);
maxn=max(maxn,ai[i]);
minn=min(minn,ai[i]);
}
int mid;
while(minn<=maxn)
{
mid=(minn+maxn)>>1;
if(check(mid)) minn=mid+1;
else maxn=mid-1;
}
printf("%d\n",ans);
return 0;
}