#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 228;
int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef __WIN32
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    string s;
    cin >> s;
    vector<ll> c(26, 0);
    for(auto& it : s)
        c[it - 'a']++;
    int n = s.size();
    ll lst = -1;
    ll cc = 0;
    vector<ll> ee(26, 0);
    unordered_map<ll, ll> ans;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        if(lst != s[i])
        {
            if(lst != -1)
            {
                for(int j = 0; j < 26; j++)
                {
                    ans[j * 31 + lst - 'a'] += ee[j] * cc;
//                    cout << ee[j] << " " << cc << "\n";
                }
                ee[lst - 'a'] += cc;
                mx = max(mx, cc * (cc - 1) / 2);
            }
            cc = 1;
        }
        else
        {
            cc++;
        }
        lst = s[i];
//        cout << i << "\n";
    }
    for(int j = 0; j < 26; j++)
        ans[j * 31 + lst - 'a'] += ee[j] * cc;
    ee[lst] += cc;
    for(auto& it : c)
        mx = max(it, mx);
    for(auto& it : ans)
        mx = max(it.snd, mx);
    cout << mx;

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 228;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef __WIN32
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    string s;
    cin >> s;
    vector<ll> c(26, 0);
    for(auto& it : s)
        c[it - 'a']++;
    int n = s.size();
    ll lst = -1;
    vector< ll > cnt;
    ll cc = 0;
    for(int i = 0; i < n; i++)
    {
        if(lst != s[i])
        {
            cnt.pb(cc);
            cc = 1;
        }
        else
        {
            cc++;
        }
        lst = s[i];
    }
    cnt.pb(cc);
    ll mx = 0;
    for(auto& it : c)
        mx = max(it, mx);
    for(auto& it : cnt)
        mx = max(mx, (it - 1) * it / 2);
    for(int i = 1; i < cnt.size(); i++)
        mx = max(mx, cnt[i - 1] * cnt[i]);
    cout << mx;

    return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
#include <string.h>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

int znaki[(int)1e5][26];
int res[26][26];

LL solve(string& s)
{
	int max_single=0, max_double=0;

	memset(znaki,0,sizeof(znaki));
	memset(res, 0, sizeof(res));

	for (int i=s.size()-1; i>=0; --i) {

		if ((i+1)<(int)s.size()) {
			memcpy(znaki[i], znaki[i+1], sizeof(znaki[0]));
		}
		++znaki[i][s[i]-'a'];
	}

	FORI(0,26) {
		max_single = max(max_single, znaki[0][i]);
	}

	//cerr<<"max single="<<max_single<<endl;

	for (int i=0; i<s.size(); ++i) {
		int zidx = s[i] - 'a';
		for (int j=0; j<26; ++j) {
			if (zidx == j) continue;
			res[zidx][j] += znaki[i][j];
			max_double = max(max_double, res[zidx][j]);
		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
#include <string.h>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

int znaki[(int)1e5][26];
int res[26][26];

LL solve(string& s)
{
	int max_single=0, max_double=0;

	for (int i=s.size()-1; i>=0; --i) {

		if ((i+1)<(int)s.size()) {
			memcpy(znaki[i], znaki[i+1], sizeof(znaki[0]));
		}
		++znaki[i][s[i]-'a'];
	}

	FORI(0,26) {
		max_single = max(max_single, znaki[0][i]);
	}

	for (int i=0; i<(s.size()-1); ++i) {
		int zidx = s[i] - 'a';
		for (int j=0; j<26; ++j) {
			res[zidx][j] += znaki[i+1][j];
			max_double = max(max_double, res[zidx][j]);
		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

LL solve(string& s)
{
	vector<vector<int>> chtoidx('z'-'a'+1);

	int max_single = 0;

	FORI(0,s.size()) {
		int chidx = s[i]-'a';
		chtoidx[chidx].push_back(i);
		max_single = max(max_single, (int)chtoidx[chidx].size());
	}

	int max_double = 0;

	for (int i='a'; i<='z'; ++i) {
		for (int j='a'; j<='z'; ++j) {

			if (i==j) continue;

			const int ch1idx = i-'a';
			const int ch2idx = j-'a';

			const auto& ch1indices = chtoidx[ch1idx];
			const auto& ch2indices = chtoidx[ch2idx];

			int pairs = 0;

			for (int i=0; i<ch1indices.size(); ++i) {
				for (int j=0; j<ch2indices.size(); ++j) {
					if (ch2indices[j]>ch1indices[i]) {
						pairs += (ch2indices.size() - j);
						break;
					}
				}
			}

			max_double = max(max_double, pairs);

		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

LL solve(string& s)
{
	vector<vector<int>> chtoidx('z'-'a'+1);

	int max_single = 0;

	FORI(0,s.size()) {
		int chidx = s[i]-'a';
		chtoidx[chidx].push_back(i);
		max_single = max(max_single, (int)chtoidx[chidx].size());
	}

	int max_double = 0;

	set<char> znaki(s.begin(), s.end());

	for (auto& z1 : znaki) {
		for (auto z2 : znaki) {

			if (z1==z2) continue;

			const int ch1idx = z1-'a';
			const int ch2idx = z2-'a';

			const auto& ch1indices = chtoidx[ch1idx];
			const auto& ch2indices = chtoidx[ch2idx];

			int pairs = 0;

			for (int i=0; i<ch1indices.size(); ++i) {
				for (int j=0; j<ch2indices.size(); ++j) {
					if (ch2indices[j]>ch1indices[i]) {
						pairs += (ch2indices.size() - j);
						break;
					}
				}
			}

			max_double = max(max_double, pairs);

		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
#include <string.h>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

ULL znaki[(int)1e5][26];
ULL res[26][26];

ULL solve(string& s)
{
	ULL max_single=0, max_double=0;

	for (int i=s.size()-1; i>=0; --i) {

		if ((i+1)<(int)s.size()) {
			memcpy(znaki[i], znaki[i+1], sizeof(znaki[0]));
		}
		++znaki[i][s[i]-'a'];
	}

	FORI(0,26) {
		max_single = max(max_single, znaki[0][i]);
	}

	for (int i=0; i<(s.size()-1); ++i) {
		int zidx = s[i] - 'a';
		for (int j=0; j<26; ++j) {
			res[zidx][j] += znaki[i+1][j];
			max_double = max(max_double, res[zidx][j]);
		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

LL solve(string& s)
{
	vector<vector<int>> chtoidx('z'-'a'+1);

	int max_single = 0;

	FORI(0,s.size()) {
		int chidx = s[i]-'a';
		chtoidx[chidx].push_back(i);
		max_single = max(max_single, (int)chtoidx[chidx].size());
	}

	int max_double = 0;

	for (int i='a'; i<='z'; ++i) {
		for (int j='a'; j<='z'; ++j) {

			if (i==j) continue;

			const int ch1idx = i-'a';
			const int ch2idx = j-'a';

			const auto& ch1indices = chtoidx[ch1idx];
			const auto& ch2indices = chtoidx[ch2idx];

			int pairs = 0;

			for (int i=0; i<ch1indices.size(); ++i) {
				for (int j=0; j<ch2indices.size(); ++j) {
					if (ch2indices[j]>ch1indices[i]) ++pairs;
				}
			}

			max_double = max(max_double, pairs);

		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

LL solve(string& s)
{
	vector<vector<int>> chtoidx('z'-'a'+1);

	int max_single = 0;
	int max_double = 0;

	FORI(0,s.size()) {
		int chidx = s[i]-'a';
		chtoidx[chidx].push_back(i);
		max_single = max(max_single, (int)chtoidx[chidx].size());

		for (int j=0; j<('z'-'a'+1); ++j) {
			if (j==chidx) continue;
			max_double = max(max_double, (int)chtoidx[j].size() *\
										      (int)chtoidx[chidx].size());
		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
#include <string.h>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

int znaki[(int)1e5][26];
int res[26][26];

LL solve(string& s)
{
	int max_single=0, max_double=0;

	for (int i=s.size()-1; i>=0; --i) {

		if ((i+1)<(int)s.size()) {
			memcpy(znaki[i], znaki[i+1], sizeof(znaki[0]));
		}
		++znaki[i][s[i]-'a'];
	}

	FORI(0,26) {
		max_single = max(max_single, znaki[0][i]);
	}

	for (int i=0; i<s.size(); ++i) {
		int zidx = s[i] - 'a';
		for (int j=0; j<26; ++j) {
			res[zidx][j] += znaki[i][j];
			max_double = max(max_double, res[zidx][j]);
		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
#include <string.h>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

int znaki[(int)1e5][26];
int res[26][26];

LL solve(string& s)
{
	int max_single=0, max_double=0;

	for (int i=s.size()-1; i>=0; --i) {

		if ((i+1)<(int)s.size()) {
			memcpy(znaki[i], znaki[i+1], sizeof(znaki[0]));
		}
		++znaki[i][s[i]-'a'];
	}

	FORI(0,26) {
		max_single = max(max_single, znaki[0][i]);
	}

	for (int i=0; i<s.size(); ++i) {
		int zidx = s[i] - 'a';
		for (int j=0; j<26; ++j) {
			if (zidx == j) continue;
			res[zidx][j] += znaki[i][j];
			max_double = max(max_double, res[zidx][j]);
		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
#include <string.h>

///// Common stuff /////////

using namespace std;

typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef pair<int,int> PII;

#define READI(name)         int name; cin >> name;
#define READLL(name)        long long name; cin >> name;
#define READVI(name,count)  vector<int> name(count); for(int i=0; i<count;++i){cin >> name[i];}
#define FORI(s,e)           for (int i=s;i<(int)e;++i)

template<class T>
static void print_stl_cont(const T& v, const string& desc="")
{
    if (!desc.empty()) { cerr<<desc<<": "; }
    int i=0;
    for(auto x: v) { cerr<<"["<<i++<<"]="<<x<<" "; }
    cerr<<endl;
}

/////// Solution ///////////

int znaki[(int)10e5+1][26];
int res[26][26];

LL solve(string& s)
{
	int max_single=0, max_double=0;

	for (int i=s.size()-1; i>=0; --i) {

		if ((i+1)<(int)s.size()) {
			memcpy(znaki[i], znaki[i+1], sizeof(znaki[0]));
		}
		++znaki[i][s[i]-'a'];
	}

	FORI(0,26) {
		max_single = max(max_single, znaki[0][i]);
	}

	for (int i=0; i<s.size(); ++i) {
		int zidx = s[i] - 'a';
		for (int j=0; j<26; ++j) {
			if (zidx == j) continue;
			res[zidx][j] += znaki[i][j];
			max_double = max(max_double, res[zidx][j]);
		}
	}

	return max(max_single, max_double);
}

//////// Main /////////////

int main() {
cin.sync_with_stdio(false);

// Read input

string s;
cin >> s;
cout<<solve(s)<<endl;

// getchar() //XXXXXXXXXXXXXXXXXXXXXX dont forget to remove
return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;

int main()
{
  flash
  string s;
  cin>>s;

  int n=s.length();

  std::map<string,short int> map;

  for(int i=0;i<n;i++){
      string t;
      t+=s[i];
    //  cout<<t<<"t\n";
      map[t]++;
    for(int diff=1;i+diff<n;diff++){

      for(int j=i+diff;j<n;j+=diff ){
        t+=s[j];
        map[t]++;
      //  cout<<t<<"\n";
      }
    //  cout<<"\n\n";
      t=s[i];

    }

  }

  int max=0;
  for (auto itr = map.begin(); itr != map.end(); ++itr) {
        if(itr->second>max)
          max=itr->second;
    }

  // cout<<map["aab"];
  cout<<max<<"\n";
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;

int main()
{
  flash
  string s;
  cin>>s;

  int n=s.length();

  std::map<string,short int> map;

  for(int i=0;i<n;i++){
      string t;
      t+=s[i];
  //    cout<<t<<"t\n";
      map[t]++;
    for(int diff=1;i+diff<n;diff++){

      for(int j=i+diff;j<n;j+=diff ){
        t+=s[j];
        if(t.length()>2)
          break;
        map[t]++;
    //    cout<<t<<"\n";
      }
    //  cout<<"\n\n";
      t=s[i];

    }

  }

  int max=0;
  for (auto itr = map.begin(); itr != map.end(); ++itr) {
        if(itr->second>max)
          max=itr->second;
    }

  // cout<<map["aab"];
  cout<<max<<"\n";
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;
int main()
{
  flash

  string s;
  cin>>s;

  ll n=s.length();

  ll arr[26][26]={{0}};
  ll arr1[26]={0};
  arr1[s[0]-'a']++;
  //arr[0][0]++;
  for(ll i=1;i<n;i++){
    ll x=s[i]-'a';

    for(ll j=0;j<26;j++)
      arr[j][x]+=arr1[j];
      arr1[x]++;

  }
ll ans=0;
  for(ll i=0;i<26;i++){
    for(ll j=0;j<26;j++){
      ans=max(ans,arr[i][j]);
    }
    //cout<<"\n";
  }

  for(ll i=0;i<26;i++)
      ans=max(ans,arr1[i]);

    cout<<ans<<"\n";

}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;

int main()
{
  flash

  string s;
  cin>>s;

  int n=s.length();

  int arr[26][26]={{0}};
  int arr1[26]={0};
  arr1[s[0]-'a']++;
  //arr[0][0]++;
  for(int i=1;i<n;i++){
    int x=s[i]-'a';

    for(int j=0;j<26;j++)
      arr[j][x]+=arr1[j];
      arr1[x]++;

  }
int ans=0;
  for(int i=0;i<26;i++){
    for(int j=0;j<26;j++){
      ans=max(ans,arr[i][j]);
    }
    //cout<<"\n";
  }

  for(int i=0;i<26;i++)
      ans=max(ans,arr1[i]);

    cout<<ans<<"\n";

}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;

int main()
{
  flash

  string s;
  cin>>s;

  int n=s.length();

  int arr[26][26]={{0}};
  int arr1[26]={0};
  arr1[s[0]-'a']++;
  //arr[0][0]++;
  for(int i=1;i<n;i++){
    int x=s[i]-'a';

    arr1[x]++;

    for(int j=0;j<i;j++){
      int t=s[j]-'a';
      //cout<<x<<" "<<t<<" ";
      arr[t][x]++;
    }

  }
int ans=0;
  for(int i=0;i<26;i++){
    for(int j=0;j<26;j++){
      ans=max(ans,arr[i][j]);
    }
    //cout<<"\n";
  }

  for(int i=0;i<26;i++)
      ans=max(ans,arr1[i]);

    cout<<ans<<"\n";

}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;

int main()
{
  flash
  string s;
  cin>>s;

  ll n=s.length();

  std::map<string, int> map;

  for(int i=0;i<n;i++){
      string t;
      t+=s[i];
    //  cout<<t<<"t\n";
      map[t]++;
    for(int diff=1;i+diff<n;diff++){

      for(int j=i+diff;j<n;j+=diff ){
        t+=s[j];
        map[t]++;
      //  cout<<t<<"\n";
      }
      //cout<<"Ad\n\n";
      t=s[i];

    }

  }

  ll max=0;
  for (auto itr = map.begin(); itr != map.end(); ++itr) {
        if(itr->second>max)
          max=itr->second;
    }

  // cout<<map["aab"];
  cout<<max<<"\n";
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;

int main()
{
  flash

  string s;
  cin>>s;

  int n=s.length();

  int arr[26][26]={{0}};
  int arr1[26]={0};
  arr1[s[0]]++;
  //arr[0][0]++;
  for(int i=1;i<n;i++){
    int x=s[i]-'a';

    arr1[x]++;

    for(int j=0;j<i;j++){
      int t=s[j]-'a';
      //cout<<x<<" "<<t<<" ";
      arr[t][x]++;
    }

  }
int ans=0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      ans=max(ans,arr[i][j]);
    }
    //cout<<"\n";
  }

  for(int i=0;i<26;i++)
    ans=max(ans,arr1[i]);

    cout<<ans<<"\n";
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;

int main()
{
  flash

  string s;
  cin>>s;

  int n=s.length();

  int arr[26][26]={{0}};
  int arr1[26]={0};
  arr1[s[0]-'a']++;
  //arr[0][0]++;
  for(int i=1;i<n;i++){
    int x=s[i]-'a';

    arr1[x]++;

    for(int j=0;j<i;j++){
      int t=s[j]-'a';
      //cout<<x<<" "<<t<<" ";
      arr[t][x]++;
    }

  }
int ans=0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      ans=max(ans,arr[i][j]);
    }
    //cout<<"\n";
  }

  for(int i=0;i<26;i++)
    ans=max(ans,arr1[i]);

    cout<<ans<<"\n";
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef set<ll> sll;
typedef set<ld> sld;
typedef multiset<ll> msll;
typedef multiset<ld> msld;
//typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define INF 1e18
#define pi 3.141592653589793

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    map<char, ll> m;
    for (ll i = 0; i < s.size(); ++i) {
        if (m.count(s[i]) == 0) m[s[i]] = 1;
        else ++m[s[i]];
    }
    ll MA1 = 0;
    for (auto x : m) if (MA1 < x.second) MA1 = x.second;
    char gl;
    for (auto x : m) {
        if (x.second == MA1) {
            gl = x.first;
            break;
        }
    }
    map<char, ll> mp;
    bool t = true;
    for (ll i = 0; i < s.size(); ++i) {
        if (s[i] == gl) t = false;
        if (t) continue;
        if (s[i] != gl) {
            if (mp.count(s[i]) == 0) mp[s[i]] = 1;
            else ++mp[s[i]];
        }
    }
    ll MA2 = 1;
    for (auto x : mp) if (MA2 < x.second) MA2 = x.second;
    cout << MA1 * MA2;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef set<ll> sll;
typedef set<ld> sld;
typedef multiset<ll> msll;
typedef multiset<ld> msld;
//typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define INF 1e18
#define pi 3.141592653589793
 ll n = 0;
 vll pod;
 map<string, ll> m;
 string s, spod = "";

 void search(ll k) {
     if (spod.size() > 2) return;
     if (k == n + 1) {
         if (pod.size()) ++m[spod];
     }
     else {
         pod.push_back(k);
         string vr = spod;
         spod += s[k - 1];
         search(k + 1);
         pod.pop_back();
         spod = vr;
         search(k + 1);
     }
 }

 int main() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     cin >> s;
     n = s.size();
     search(1);
     ll ans = 0;
     for (auto x : m) {
         if (ans < x.second) ans = x.second;
     }
     cout << ans;
 }


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef set<ll> sll;
typedef set<ld> sld;
typedef multiset<ll> msll;
typedef multiset<ld> msld;
//typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define INF 1e18
#define pi 3.141592653589793

ll n = 0;
vll pod;
map<string, ll> m;
string s, spod = "";
bool sp = true;

void solve(vll p) {
    if (m.count(spod) == 0) m[spod] = 1;
    else ++m[spod];
}

bool prpr (vll p) {
    ll q = p[1] - p[0];
    bool t = true;
    for (ll i = 0; i < p.size() - 1; ++i) {
        if (p[i + 1] - p[i] != q) {
            t = false;
            break;
        }
    }
    return t;
}

void search(ll k) {
    if (k == n + 1) {
        if (pod.size()) solve(pod);
    }
    else {
        pod.push_back(k);
        string vr = spod;
        spod += s[k - 1];
        if (pod.size() >= 2){
            if (k + pod[1] - pod[0] < n + 1) search(k + pod[1] - pod[0]);
            else search(k + 1);
        }
        else search(k + 1);
        pod.pop_back();
        spod = vr;
        if (pod.size() >= 2){
            if (k + pod[1] - pod[0] < n + 1) search(k + pod[1] - pod[0]);
            else search(k + 1);
        }
        else search(k + 1);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    n = s.size();
    search(1);
    ll ans = 0;
    for (auto x : m) {
        if (ans < x.second) ans = x.second;
    }
    cout << ans;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef set<ll> sll;
typedef set<ld> sld;
typedef multiset<ll> msll;
typedef multiset<ld> msld;
//typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define INF 1e18
#define pi 3.141592653589793
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    map<char, ll> m1;
    map<string, ll> m2;
    ll ans1 = 0, ans2 = 0;
    for (ll i = 0; i < s.size(); ++i) {
        for (ll j = 0; j < 26; ++j) {
            string s2 = "";
            char vr = (char)(((int)'a') + j);
            s2 += vr;
            s2 += s[i];
            m2[s2] += m1[vr];
            if (ans2 < m2[s2]) ans2 = m2[s2];
        }
        ++m1[s[i]];
        if (ans1 < m1[s[i]]) ans1 = m1[s[i]];
    }
    cout << max(ans1, ans2);
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef set<ll> sll;
typedef set<ld> sld;
typedef multiset<ll> msll;
typedef multiset<ld> msld;
//typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define INF 1e18
#define pi 3.141592653589793

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    map<char, ll> m;
    for (ll i = 0; i < s.size(); ++i) {
        if (m.count(s[i]) == 0) m[s[i]] = 1;
        else ++m[s[i]];
    }
    ll MA1 = -INF, MA2 = -INF;
    for (auto x : m) {
        if (x.second > MA1) {
            MA2 = MA1;
            MA1 = x.second;
        }
        else {
            if (x.second > MA2) {
                MA2 = x.second;
            }
        }
    }
    if (MA2 != -INF) {
        cout << MA1 * MA2;
    }
    else cout << MA1;
}


import kotlin.math.max

fun main() {
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    var (numKegs, numGlasses) = readLongs()
    val volumes = readLongs()
    val min = volumes.minOrNull()!!
    for (volume in volumes) {
        numGlasses -= (volume - min)
        if (numGlasses <= 0L) return print(min)
    }
    print(max(-1, min - (numGlasses / numKegs) - if (numGlasses % numKegs == 0L) 0 else 1))
}


fun main() {
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    var (numKegs, numGlasses) = readLongs()
    val volumes = readLongs()
    val min = volumes.minOrNull()!!
    val extras = volumes.fold(0L) { acc: Long, l: Long -> acc - min + l }
    numGlasses -= extras
    print(if (numGlasses <= 0) min else min - (numGlasses / numKegs) - if (numGlasses % numKegs == 0L) 0 else 1)
}


fun main() {
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    var (numKegs, numGlasses) = readLongs()
    val volumes = readLongs()
    val min = volumes.minOrNull()!!
    for (volume in volumes) {
        numGlasses = numGlasses - volume + min
        if (numGlasses <= 0L) return print(min)
    }
    print(min - (numGlasses / numKegs) - if (numGlasses % numKegs == 0L) 0 else 1)
}


fun main() {
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    var (numKegs, numGlasses) = readLongs()
    val volumes = readLongs()
    val min = volumes.minOrNull()!!
    val extras = volumes.fold(0L) { acc: Long, l: Long -> acc - min + l }
    numGlasses -= extras
    print(if (extras <= 0) min else min - (numGlasses / numKegs) - if (numGlasses % numKegs == 0L) 0 else 1)
}


fun main() {
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    var (numKegs, numGlasses) = readLongs()
    val volumes = readLongs()
    val min = volumes.minOrNull()!!
    for (volume in volumes) {
        numGlasses -= (volume - min)
        if (numGlasses <= 0L) return print(min)
    }
    if (numKegs == 1000L) println("$min $numGlasses")
    print(min - (numGlasses / numKegs) - if (numGlasses % numKegs == 0L) 0 else 1)
}


//Kotlin is also fun!!
import java.util.*
fun main(args: Array<String>) = with(Scanner(System.`in`))
{
    val (x,s) = readLine()!!.split(" ").map{it.toLong()}
    val n = x.toInt()
    val a = LongArray(n){nextLong()}
    var m = 1000000000000000L
    for(i in 0..n-1)
        m=Math.min(m,a[i])
    var sum = 0L
    for(i in 0..n-1)
        sum+=(a[i]-m)
    if(sum>=s)
        print(m)
    else if(sum+m*n<s)
        print(-1)
    else
        print(m-(s-sum+n-1)/n)
}


//Kotlin is also fun!!
import java.util.*
fun main(args: Array<String>) = with(Scanner(System.`in`))
{
    val (n,s) = readLine()!!.split(" ").map{it.toInt()}
    val a = LongArray(n){nextLong()}
    var m = 1000000000000000L
    for(i in 0..n-1)
        m=Math.min(m,a[i])
    var sum = 0L
    for(i in 0..n-1)
        sum+=(a[i]-m)
    if(sum>=s)
        print(m)
    else if(sum+m*n<s)
        print(-1)
    else
        print(m-(s-sum+n-1)/n)
}


//Kotlin is also fun!!
import java.util.*
fun main(args: Array<String>) = with(Scanner(System.`in`))
{
    val (n,s) = readLine()!!.split(" ").map{it.toInt()}
    s.toLong()
    val a = LongArray(n){nextLong()}
    var m = 1000000000000000L
    for(i in 0..n-1)
        m=Math.min(m,a[i])
    var sum = 0L
    for(i in 0..n-1)
        sum+=(a[i]-m)
    if(sum>=s)
        print(m)
    else if(sum+m*n<s)
        print(-1)
    else
        print(m-(s-sum+n-1)/n)
}


fun main(args: Array<String>) {
//    var n = readLine()!!.toInt()
    var arr2 = readLine()!!.split(" ").map { x -> x.toInt() }
    var arr = readLine()!!.split(" ").map { x -> x.toInt() }

    var n = arr2[0]
    var s = arr2[1]

    var min = arr.min()
    var sum = arr.sum()

    if (sum < s) {
        print(-1)
        return
    }

    var minimum = (sum - s) / n
    if (min!! < minimum) print(min)
    else print(minimum)

}


fun main(args: Array<String>) {
//    var n = readLine()!!.toInt()
    var arr2 = readLine()!!.split(" ").map { x -> x.toLong() }
    var arr = readLine()!!.split(" ").map { x -> x.toLong() }

    var n = arr2[0]
    var s = arr2[1]

    var min = arr.min()
    var sum = arr.sum()

    if (sum < s) {
        print(-1)
        return
    }

    var minimum = (sum - s) / n
    if (min!! < minimum) print(min)
    else print(minimum)

}


fun main(args: Array<String>) {
//    var n = readLine()!!.toInt()
    var arr2 = readLine()!!.split(" ").map { x -> x.toLong() }
    var arr = readLine()!!.split(" ").map { x -> x.toInt() }

    var n = arr2[0]
    var s = arr2[1]

    var min = arr.min()
    var sum = arr.sum()

    if (sum < s) {
        print(-1)
        return
    }

    var minimum = (sum - s) / n
    if (min!! < minimum) print(min)
    else print(minimum)

}


/*input
7
3 3
1 1 1
3 1
1 1 2
3 1
1 2 3
3 3
4 3 1000000000
3 3
4 3 5
3 4
5 3 4
3 7
1 2 3

*/
import java.util.PriorityQueue;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * @author masterbios
 */
public class TaskB {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskBB solver = new TaskBB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskBB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            // int t = in.nextInt();
            // while(t-- > 0){
            int n = in.nextInt();
            long s = in.nextLong();
            long a[] = new long[n];
            long max = Long.MAX_VALUE;
            for(int i = 0; i < n; i++){
                a[i] = in.nextLong();
                max = Math.min(max, a[i]);
            }
            long low = 0;
            long high = max;
            long res = -1;
            // out.println(max);
            boolean ans = false;
            while(low <= high ){
                long mid = low + (high - low) / 2;
                // out.print("low " + low + " high " + high + " mid " + mid);
                long temp = 0;
                for(int i = 0; i < n; i++){
                    temp += a[i] - mid;
                    // if(temp >= s)break;
                }
                // out.print(" temp " + temp);

                if(temp >= s){
                    res = mid;
                    low = mid + 1;
                } else {
                    high = mid - 1;
                }
                // out.println(" res " + res + " low " + low + " high " + high);
            }
            out.println(res);
        // }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreElements()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
    }
}


/*input

3 1
1 1 2

*/
import java.util.PriorityQueue;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * @author masterbios
 */
public class TaskB {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskBB solver = new TaskBB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskBB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            // int t = in.nextInt();
            // while(t-- > 0){
            int n = in.nextInt();
            long s = in.nextLong();
            long a[] = new long[n];
            long max = Long.MIN_VALUE;
            for(int i = 0; i < n; i++){
                a[i] = in.nextLong();
                max = Math.max(max, a[i]);
            }
            long low = 0;
            long high = max;
            long res = -1;
            // out.println(max);
            boolean ans = false;
            while(high - low + 1> 0 ){
                long mid = low + (high - low) / 2;
                // out.print("low " + low + " high " + high + " mid " + mid);
                long temp = 0;
                for(int i = 0; i < n; i++){
                    temp += a[i] - mid > 0 ? a[i] - mid : 0;
                    // if(temp >= s)break;
                }
                // out.print(" temp " + temp);

                if(temp > s){
                    res = mid;
                    low = mid + 1;
                } else if (temp == s){
                    low = mid;
                    res = mid;
                    // out.println();
                    break;
                } else {
                    high = mid - 1;
                }
                // out.println(" res " + res + " low " + low + " high " + high);
            }
            out.println(res);
        }
        // }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreElements()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
    }
}


/*input
3 3
1 2 3
*/
import java.util.PriorityQueue;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * @author masterbios
 */
public class TaskB {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskBB solver = new TaskBB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskBB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long s = in.nextLong();
            long a[] = new long[n];
            long max = Long.MIN_VALUE;
            for(int i = 0; i < n; i++){
                a[i] = in.nextLong();
                max = Math.max(max, a[i]);
            }
            long low = 0;
            long high = max;
            long res = -1;
            // out.println(max);
            boolean ans = false;
            while(high - low > 1){
                long mid = low + (high - low) / 2;
                // out.print("low " + low + " high " + high + " mid " + mid);
                long temp = 0;
                for(int i = 0; i < n; i++){
                    temp += a[i] - mid;
                }
                // out.print(" temp " + temp);

                if(temp >= s){
                    res = mid;
                    low = mid;
                } else {
                    low = mid;
                }
                // out.println(" res " + res + " low " + low + " high " + high);
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreElements()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
    }
}


/*input
3 5
1 2 10
*/
import java.util.PriorityQueue;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * @author masterbios
 */
public class TaskB {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskBB solver = new TaskBB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskBB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long s = in.nextLong();
            long a[] = new long[n];
            long max = Long.MIN_VALUE;
            for(int i = 0; i < n; i++){
                a[i] = in.nextLong();
                max = Math.max(max, a[i]);
            }
            long low = 0;
            long high = max;
            long res = -1;
            // out.println(max);
            boolean ans = false;
            while(high - low > 1 ){
                long mid = low + (high - low) / 2;
                // out.print("low " + low + " high " + high + " mid " + mid);
                long temp = 0;
                for(int i = 0; i < n; i++){
                    temp += a[i] - mid > 0 ? a[i] - mid : 0;
                }
                // out.print(" temp " + temp);

                if(temp >= s){
                    res = mid;
                    low = mid;
                } else {
                    low = mid + 1;
                }
                // out.println(" res " + res + " low " + low + " high " + high);
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreElements()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p001084b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s = in.nextLong();
        long[] a = new long[n];
        for(int i = 0; i < n; i++)
            a[i] = in.nextLong();
        Arrays.sort(a);
        long min = a[0];
        for(int i = n-1; i > 0; i--)
        {
            if(s <= a[i] - min) {
                System.out.println(min);
                return;
            }
            s -= a[i]-min;
            a[i] = min;
        }
        if(s/n + s%n > min) {System.out.println(-1); return;}
        System.out.println(min - (s/n + s%n));
    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p001084b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s = in.nextLong();
        long[] a = new long[n];
        long tot = 0;
        for(int i = 0; i < n; i++)
        {
            a[i] = in.nextLong();
            tot += a[i];
        }
        Arrays.sort(a);
        long min = a[0];
        if(s > tot) {System.out.println(-1); return;}
        for(int i = n-1; i > 0; i--)
        {
            if(s <= a[i] - min) {
                System.out.println(min);
                return;
            }
            tot += a[i];
            s -= a[i]-min;
            a[i] = min;
        }
        System.out.println(Math.max(min - s/n - (s%n != 0) ? 1 : 0, 0));
    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p001084b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s = in.nextLong();
        long[] a = new long[n];
        long tot = 0;
        for(int i = 0; i < n; i++)
        {
            a[i] = in.nextLong();
            tot += a[i];
        }
        Arrays.sort(a);
        long min = a[0];
        if(s > tot) {System.out.println(-1); return;}
        for(int i = n-1; i > 0; i--)
        {
            if(s <= a[i] - min) {
                System.out.println(min);
                return;
            }
            tot += a[i];
            s -= a[i]-min;
            a[i] = min;
        }
        System.out.println(Math.max(min - s/n - ((s%n != 0) ? 1 : 0), 0));
    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p001084b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s = in.nextLong();
        long[] a = new long[n];
        for(int i = 0; i < n; i++)
            a[i] = in.nextLong();
        Arrays.sort(a);
        long min = a[0];
        long tot = min;
        for(int i = n-1; i > 0; i--)
        {
            if(s <= a[i] - min) {
                System.out.println(min);
                return;
            }
            tot += a[i];
            s -= a[i]-min;
            a[i] = min;
        }
        if(s > tot) {System.out.println(-1); return;}
        System.out.println(min - s/n - 1);
    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p001084b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s = in.nextLong();
        long[] a = new long[n];
        for(int i = 0; i < n; i++)
            a[i] = in.nextLong();
        Arrays.sort(a);
        long min = a[0];
        for(int i = n-1; i > 0; i--)
        {
            if(s < a[i] - min) {
                System.out.println(min);
                return;
            }
            s -= a[i]-min;
            a[i] = min;
        }
        if(s/n + s%n > min) {System.out.println(-1); return;}
        System.out.println(min - (s/n + s%n));
    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p001084b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s = in.nextLong();
        long[] a = new long[n];
        for(int i = 0; i < n; i++)
            a[i] = in.nextLong();
        Arrays.sort(a);
        long min = a[0];
        long tot = min;
        for(int i = n-1; i > 0; i--)
        {
            if(s <= a[i] - min) {
                System.out.println(min);
                return;
            }
            tot += a[i];
            s -= a[i]-min;
            a[i] = min;
        }
        if(s > tot) {System.out.println(-1); return;}
        System.out.println(Math.max(min - s/n - 1, 0));
    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p001084b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s = in.nextLong();
        long[] a = new long[n];
        long tot = 0;
        for(int i = 0; i < n; i++)
        {
            a[i] = in.nextLong();
            tot += a[i];
        }
        Arrays.sort(a);
        long min = a[0];
        if(s > tot) {System.out.println(-1); return;}
        for(int i = n-1; i > 0; i--)
        {
            if(s <= a[i] - min) {
                System.out.println(min);
                return;
            }
            tot += a[i];
            s -= a[i]-min;
            a[i] = min;
        }
        System.out.println(Math.max(min - s/n - 1, 0));
    }
}


//package code;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;
/**
 *
 * @author prabhat // use stringbuilder,TreeSet, priorityQueue, x+y=(x&y + x|y);
 */
 public class  a
   {
   public static int n,max1=100005,k,m,q,a[],a1[],mat[][],id,depth[],parent[][],len=22,tin[],tout[],count=0,size[];
   public static Point[] p1,p2,p;
   public static long mod=(long)1e9+7,nCr[][],suf[][],ans=Long.MAX_VALUE,max=Long.MIN_VALUE,dp[][];
   public static boolean isPrime[],visit[],valid[][];
   public static HashSet<Integer> hash;

   public static  ArrayList<Integer> divisor[],prime,adj[],lpf;
   public static ArrayList<Character> list[];
   public static  TreeSet<Integer> ts;
   public static String s;
   public  static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   static PrintWriter pw;
   static int[] x={0,1},y={1,0};

   public static void main(String[] args) {
	new Thread(null,null,"Prabhat Kumar",99999999)
	{
	   public void run()
	   {
		   try
		   {
			   solve();
		   }
		   catch(Exception e)
		   {
			   e.printStackTrace();
			   System.exit(1);
		   }
	   }
	}.start();
}
static void solve() throws IOException
 {
	InputReader in = new InputReader(System.in);
	pw=new PrintWriter(System.out);
	n=in.ii();
	long s=in.il();
	long[] a=in.ila(n);
	Arrays.sort(a);
	long min=a[0];
	long sum=0;
	long sum1=a[0];
	for(int i=1;i<n;i++)
	{
	  sum+=a[i]-min;
	  sum1+=a[i];
	}

    if(sum1<s)pw.println(-1);
	else if(sum1==s)pw.println(0);
	else if(sum>=s)pw.println(min);
	else if(sum<s){
		long x=s-sum;
		pw.println(min-x);
	}
	else pw.println(-1);
	pw.close();
 }
static void dfs1(int cur,int par,TreeSet<Integer> ts)
{
	if(visit[cur])return;
	visit[cur]=true;
	ts.add(cur);
	for(int ver:adj[cur])
	{
		if(visit[ver])continue;
		if(ver!=par)dfs1(ver,cur,ts);
	}
}
 static int palin(String s)
 {
	String s1=new StringBuilder(s).reverse().toString();
	return s1.equals(s)==true?1:0;
 }
 static int dfs(int u, int p) {

	//discover[count1++]=arr[u];  //  it storing color or arr of vertex u
	//discover[count1++]=u;
	//tin[u] = count++;
   int d1=1000000;
   int d2=1000000;
   int cnt=0;
	//parent[u][0] = p==-1?0:p;
	//size[u]++;
	//for (int i = 1; i < len; i++)
	//	parent[u][i] = parent[parent[u][i-1]][i-1];
	for (int v :adj[u])
		if (v != p)
		{
			cnt++;
			depth[v] = depth[u] + 1;
			int y=dfs( v, u);
			if(y<d1)
			{
				d2=d1;
				d1=y;
			}
			else if(y<d2)
			{
				d2=y;
			}
	//		size[u] += size[v];
		}
	if(cnt==0)return 1;
	ans=Math.min(d1+d2,ans);
	return 1+Math.min(d1,d2);
//	if(adj[u].size()==1&&parent[u][0]!=0)last.add(u);
//	tout[u] = count-1;
}

static boolean isParent(int parent, int child) {
	return tin[parent] <= tin[child] && tout[child] <= tout[parent];
}

static int lca(int a, int b) {
	if (isParent(a, b))
		return a;
	if (isParent(b, a))
		return b;
	for (int i = len - 1; i >= 0; i--)
		if (!isParent(parent[a][i], b))
			a = parent[a][i];
	return parent[a][0];
}
static boolean valid(int i,int j)
{
	return i>=1&&i<=n&&j>=1&&j<=m;
}

static int gcd(int a,int b)
{
	while(a!=0)
	{
		int temp=a;
		a=b%a;
		b=temp;
	}
	return b;
}
static void Seive()
{
	a1=new int[max1];
	isPrime=new boolean[max1];
	Arrays.fill(isPrime,true);
//	prime=new ArrayList<>();
//	divisor=new ArrayList[max1];
//	for(int i=1;i<max1;i++)divisor[i]=new ArrayList<Integer>();
    isPrime[0]=isPrime[1]=false;
	for(int i=2;i<(max1);i++)
	{
         if(isPrime[i]){
		//	 divisor[i].add(i);
		//	 prime.add(i);
			 a1[i]=1;
			for(int j=2*i;j<max1;j+=i)
			{
				a1[j]++;
				isPrime[j]=false;
				//divisor[j].add(i);
			}
		}
	}
}
public static long pow(long n,long p)
{
	 long  result = 1;
	  if(p==0)
	    return 1;

	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;

	    p >>=1;
	    n*=n;
	}
	return result;
}

static  class InputReader
{
   private InputStream stream;
   private byte[] buf = new byte[1024];

   private SpaceCharFilter filter;
    byte inbuffer[] = new byte[1024];
   int lenbuffer = 0, ptrbuffer = 0;
    final int M = (int) 1e9 + 7;
   int md=(int)(1e7+1);
    int[] SMP=new int[md];
   final double eps = 1e-6;
   final double pi = Math.PI;

	PrintWriter out;
   String check = "";
 InputStream   obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
   public InputReader(InputStream stream)
   {
       this.stream = stream;
   }

    int readByte() {
	        if (lenbuffer == -1) throw new InputMismatchException();
	        if (ptrbuffer >= lenbuffer) {
	            ptrbuffer = 0;
	            try {
	                lenbuffer = obj.read(inbuffer);
	            } catch (IOException e) {
	                throw new InputMismatchException();
	            }
	        }
	        if (lenbuffer <= 0) return -1;
	        return inbuffer[ptrbuffer++];
   }

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

   String is() {
	        int b = skip();
	        StringBuilder sb = new StringBuilder();
	        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
	        {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
   }
   public   int ii() {
	        int num = 0, b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }
 public   long il() {
	        long num = 0;
	        int b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }

	    boolean isSpaceChar(int c) {
	        return (!(c >= 33 && c <= 126));
	       }

	      int skip()
	        {
	        int b;
	        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
	        return b;
	        }

	    float nf() {
	        return Float.parseFloat(is());
	    }

	    double id() {
	        return Double.parseDouble(is());
	    }

	    char ic() {
	        return (char) skip();
	    }

	    int[] iia(int n) {
	        int a[] = new int[n];
	        for (int i = 0; i<n; i++) a[i] = ii();
	        return a;
	    }

	    long[] ila(int n) {
	        long a[] = new long[n];
	        for (int i = 0; i <n; i++) a[i] = il();
	        return a;
	    }

	    String[] isa(int n) {
	        String a[] = new String[n];
	        for (int i = 0; i < n; i++) a[i] = is();
	        return a;
	    }

		 long mul(long a, long b) { return a * b % M; }

		/*	long div(long a, long b)
				 {
					return mul(a, pow(b, M - 2,M));

		           }
*/

	    double[][] idm(int n, int m) {
	        double a[][] = new double[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
	        return a;
	        }

	    int[][] iim(int n, int m) {
	        int a[][] = new int[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
	        return a;
          }

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

   public interface SpaceCharFilter
   {
       public boolean isSpaceChar(int ch);
   }
   public boolean isEndOfLine(int c) {
       return c == '\n' || c == '\r' || c == -1;
   }
}

}


//package code;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;
/**
 *
 * @author prabhat // use stringbuilder,TreeSet, priorityQueue, x+y=(x&y + x|y);
 */
 public class  a
   {
   public static int n,max1=100005,k,m,q,a[],a1[],mat[][],id,depth[],parent[][],len=22,tin[],tout[],count=0,size[];
   public static Point[] p1,p2,p;
   public static long mod=(long)1e9+7,nCr[][],suf[][],ans=Long.MAX_VALUE,max=Long.MIN_VALUE,dp[][];
   public static boolean isPrime[],visit[],valid[][];
   public static HashSet<Integer> hash;

   public static  ArrayList<Integer> divisor[],prime,adj[],lpf;
   public static ArrayList<Character> list[];
   public static  TreeSet<Integer> ts;
   public static String s;
   public  static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   static PrintWriter pw;
   static int[] x={0,1},y={1,0};

   public static void main(String[] args) {
	new Thread(null,null,"Prabhat Kumar",99999999)
	{
	   public void run()
	   {
		   try
		   {
			   solve();
		   }
		   catch(Exception e)
		   {
			   e.printStackTrace();
			   System.exit(1);
		   }
	   }
	}.start();
}
static void solve() throws IOException
 {
	InputReader in = new InputReader(System.in);
	pw=new PrintWriter(System.out);
	n=in.ii();
	long s=in.il();
	long[] a=in.ila(n);
	Arrays.sort(a);
	long min=a[0];
	long sum=0;
	long sum1=a[0];
	for(int i=1;i<n;i++)
	{
	  sum+=a[i]-min;
	  sum1+=a[i];
	}
	if(sum>=s)pw.println(min);
	else if(sum1<s)pw.println(-1);
	else if(sum1==s)pw.println(0);
	else if(sum<s){
		long x=s-sum;
		pw.println(min-x);
	}
	pw.close();
 }
static void dfs1(int cur,int par,TreeSet<Integer> ts)
{
	if(visit[cur])return;
	visit[cur]=true;
	ts.add(cur);
	for(int ver:adj[cur])
	{
		if(visit[ver])continue;
		if(ver!=par)dfs1(ver,cur,ts);
	}
}
 static int palin(String s)
 {
	String s1=new StringBuilder(s).reverse().toString();
	return s1.equals(s)==true?1:0;
 }
 static int dfs(int u, int p) {

	//discover[count1++]=arr[u];  //  it storing color or arr of vertex u
	//discover[count1++]=u;
	//tin[u] = count++;
   int d1=1000000;
   int d2=1000000;
   int cnt=0;
	//parent[u][0] = p==-1?0:p;
	//size[u]++;
	//for (int i = 1; i < len; i++)
	//	parent[u][i] = parent[parent[u][i-1]][i-1];
	for (int v :adj[u])
		if (v != p)
		{
			cnt++;
			depth[v] = depth[u] + 1;
			int y=dfs( v, u);
			if(y<d1)
			{
				d2=d1;
				d1=y;
			}
			else if(y<d2)
			{
				d2=y;
			}
	//		size[u] += size[v];
		}
	if(cnt==0)return 1;
	ans=Math.min(d1+d2,ans);
	return 1+Math.min(d1,d2);
//	if(adj[u].size()==1&&parent[u][0]!=0)last.add(u);
//	tout[u] = count-1;
}

static boolean isParent(int parent, int child) {
	return tin[parent] <= tin[child] && tout[child] <= tout[parent];
}

static int lca(int a, int b) {
	if (isParent(a, b))
		return a;
	if (isParent(b, a))
		return b;
	for (int i = len - 1; i >= 0; i--)
		if (!isParent(parent[a][i], b))
			a = parent[a][i];
	return parent[a][0];
}
static boolean valid(int i,int j)
{
	return i>=1&&i<=n&&j>=1&&j<=m;
}

static int gcd(int a,int b)
{
	while(a!=0)
	{
		int temp=a;
		a=b%a;
		b=temp;
	}
	return b;
}
static void Seive()
{
	a1=new int[max1];
	isPrime=new boolean[max1];
	Arrays.fill(isPrime,true);
//	prime=new ArrayList<>();
//	divisor=new ArrayList[max1];
//	for(int i=1;i<max1;i++)divisor[i]=new ArrayList<Integer>();
    isPrime[0]=isPrime[1]=false;
	for(int i=2;i<(max1);i++)
	{
         if(isPrime[i]){
		//	 divisor[i].add(i);
		//	 prime.add(i);
			 a1[i]=1;
			for(int j=2*i;j<max1;j+=i)
			{
				a1[j]++;
				isPrime[j]=false;
				//divisor[j].add(i);
			}
		}
	}
}
public static long pow(long n,long p)
{
	 long  result = 1;
	  if(p==0)
	    return 1;

	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;

	    p >>=1;
	    n*=n;
	}
	return result;
}

static  class InputReader
{
   private InputStream stream;
   private byte[] buf = new byte[1024];

   private SpaceCharFilter filter;
    byte inbuffer[] = new byte[1024];
   int lenbuffer = 0, ptrbuffer = 0;
    final int M = (int) 1e9 + 7;
   int md=(int)(1e7+1);
    int[] SMP=new int[md];
   final double eps = 1e-6;
   final double pi = Math.PI;

	PrintWriter out;
   String check = "";
 InputStream   obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
   public InputReader(InputStream stream)
   {
       this.stream = stream;
   }

    int readByte() {
	        if (lenbuffer == -1) throw new InputMismatchException();
	        if (ptrbuffer >= lenbuffer) {
	            ptrbuffer = 0;
	            try {
	                lenbuffer = obj.read(inbuffer);
	            } catch (IOException e) {
	                throw new InputMismatchException();
	            }
	        }
	        if (lenbuffer <= 0) return -1;
	        return inbuffer[ptrbuffer++];
   }

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

   String is() {
	        int b = skip();
	        StringBuilder sb = new StringBuilder();
	        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
	        {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
   }
   public   int ii() {
	        int num = 0, b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }
 public   long il() {
	        long num = 0;
	        int b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }

	    boolean isSpaceChar(int c) {
	        return (!(c >= 33 && c <= 126));
	       }

	      int skip()
	        {
	        int b;
	        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
	        return b;
	        }

	    float nf() {
	        return Float.parseFloat(is());
	    }

	    double id() {
	        return Double.parseDouble(is());
	    }

	    char ic() {
	        return (char) skip();
	    }

	    int[] iia(int n) {
	        int a[] = new int[n];
	        for (int i = 0; i<n; i++) a[i] = ii();
	        return a;
	    }

	    long[] ila(int n) {
	        long a[] = new long[n];
	        for (int i = 0; i <n; i++) a[i] = il();
	        return a;
	    }

	    String[] isa(int n) {
	        String a[] = new String[n];
	        for (int i = 0; i < n; i++) a[i] = is();
	        return a;
	    }

		 long mul(long a, long b) { return a * b % M; }

		/*	long div(long a, long b)
				 {
					return mul(a, pow(b, M - 2,M));

		           }
*/

	    double[][] idm(int n, int m) {
	        double a[][] = new double[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
	        return a;
	        }

	    int[][] iim(int n, int m) {
	        int a[][] = new int[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
	        return a;
          }

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

   public interface SpaceCharFilter
   {
       public boolean isSpaceChar(int ch);
   }
   public boolean isEndOfLine(int c) {
       return c == '\n' || c == '\r' || c == -1;
   }
}

}


//package code;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;
/**
 *
 * @author prabhat // use stringbuilder,TreeSet, priorityQueue, x+y=(x&y + x|y);
 */
 public class  a
   {
   public static int n,max1=100005,k,m,q,a[],a1[],mat[][],id,depth[],parent[][],len=22,tin[],tout[],count=0,size[];
   public static Point[] p1,p2,p;
   public static long mod=(long)1e9+7,nCr[][],suf[][],ans=Long.MAX_VALUE,max=Long.MIN_VALUE,dp[][];
   public static boolean isPrime[],visit[],valid[][];
   public static HashSet<Integer> hash;

   public static  ArrayList<Integer> divisor[],prime,adj[],lpf;
   public static ArrayList<Character> list[];
   public static  TreeSet<Integer> ts;
   public static String s;
   public  static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   static PrintWriter pw;
   static int[] x={0,1},y={1,0};

   public static void main(String[] args) {
	new Thread(null,null,"Prabhat Kumar",99999999)
	{
	   public void run()
	   {
		   try
		   {
			   solve();
		   }
		   catch(Exception e)
		   {
			   e.printStackTrace();
			   System.exit(1);
		   }
	   }
	}.start();
}
static void solve() throws IOException
 {
	InputReader in = new InputReader(System.in);
	pw=new PrintWriter(System.out);
	n=in.ii();
	long s=in.il();
	long[] a=in.ila(n);
	long min=Long.MAX_VALUE;
	for(long i:a)min=Math.min(min,i);
	long low=0;
	long high=min+1;
	long ans=0;
	while(low<high)
	{
		long mid=(low+high)/2;
		long sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=Math.max(0L,a[i]-mid);
		}
		if(sum<s)high=mid;
		else
		{
			ans=mid;
			low=mid+1;
		}
	}
//	pw.println("ans=="+ans);
	long sum=0;
	for(int i=0;i<n;i++)sum+=Math.max(0L,a[i]-ans);
	if(sum<s)pw.println(-1);
	else pw.println(ans);
	pw.close();
 }
static void dfs1(int cur,int par,TreeSet<Integer> ts)
{
	if(visit[cur])return;
	visit[cur]=true;
	ts.add(cur);
	for(int ver:adj[cur])
	{
		if(visit[ver])continue;
		if(ver!=par)dfs1(ver,cur,ts);
	}
}
 static int palin(String s)
 {
	String s1=new StringBuilder(s).reverse().toString();
	return s1.equals(s)==true?1:0;
 }
 static int dfs(int u, int p) {

	//discover[count1++]=arr[u];  //  it storing color or arr of vertex u
	//discover[count1++]=u;
	//tin[u] = count++;
   int d1=1000000;
   int d2=1000000;
   int cnt=0;
	//parent[u][0] = p==-1?0:p;
	//size[u]++;
	//for (int i = 1; i < len; i++)
	//	parent[u][i] = parent[parent[u][i-1]][i-1];
	for (int v :adj[u])
		if (v != p)
		{
			cnt++;
			depth[v] = depth[u] + 1;
			int y=dfs( v, u);
			if(y<d1)
			{
				d2=d1;
				d1=y;
			}
			else if(y<d2)
			{
				d2=y;
			}
	//		size[u] += size[v];
		}
	if(cnt==0)return 1;
	ans=Math.min(d1+d2,ans);
	return 1+Math.min(d1,d2);
//	if(adj[u].size()==1&&parent[u][0]!=0)last.add(u);
//	tout[u] = count-1;
}

static boolean isParent(int parent, int child) {
	return tin[parent] <= tin[child] && tout[child] <= tout[parent];
}

static int lca(int a, int b) {
	if (isParent(a, b))
		return a;
	if (isParent(b, a))
		return b;
	for (int i = len - 1; i >= 0; i--)
		if (!isParent(parent[a][i], b))
			a = parent[a][i];
	return parent[a][0];
}
static boolean valid(int i,int j)
{
	return i>=1&&i<=n&&j>=1&&j<=m;
}

static int gcd(int a,int b)
{
	while(a!=0)
	{
		int temp=a;
		a=b%a;
		b=temp;
	}
	return b;
}
static void Seive()
{
	a1=new int[max1];
	isPrime=new boolean[max1];
	Arrays.fill(isPrime,true);
//	prime=new ArrayList<>();
//	divisor=new ArrayList[max1];
//	for(int i=1;i<max1;i++)divisor[i]=new ArrayList<Integer>();
    isPrime[0]=isPrime[1]=false;
	for(int i=2;i<(max1);i++)
	{
         if(isPrime[i]){
		//	 divisor[i].add(i);
		//	 prime.add(i);
			 a1[i]=1;
			for(int j=2*i;j<max1;j+=i)
			{
				a1[j]++;
				isPrime[j]=false;
				//divisor[j].add(i);
			}
		}
	}
}
public static long pow(long n,long p)
{
	 long  result = 1;
	  if(p==0)
	    return 1;

	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;

	    p >>=1;
	    n*=n;
	}
	return result;
}

static  class InputReader
{
   private InputStream stream;
   private byte[] buf = new byte[1024];

   private SpaceCharFilter filter;
    byte inbuffer[] = new byte[1024];
   int lenbuffer = 0, ptrbuffer = 0;
    final int M = (int) 1e9 + 7;
   int md=(int)(1e7+1);
    int[] SMP=new int[md];
   final double eps = 1e-6;
   final double pi = Math.PI;

	PrintWriter out;
   String check = "";
 InputStream   obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
   public InputReader(InputStream stream)
   {
       this.stream = stream;
   }

    int readByte() {
	        if (lenbuffer == -1) throw new InputMismatchException();
	        if (ptrbuffer >= lenbuffer) {
	            ptrbuffer = 0;
	            try {
	                lenbuffer = obj.read(inbuffer);
	            } catch (IOException e) {
	                throw new InputMismatchException();
	            }
	        }
	        if (lenbuffer <= 0) return -1;
	        return inbuffer[ptrbuffer++];
   }

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

   String is() {
	        int b = skip();
	        StringBuilder sb = new StringBuilder();
	        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
	        {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
   }
   public   int ii() {
	        int num = 0, b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }
 public   long il() {
	        long num = 0;
	        int b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }

	    boolean isSpaceChar(int c) {
	        return (!(c >= 33 && c <= 126));
	       }

	      int skip()
	        {
	        int b;
	        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
	        return b;
	        }

	    float nf() {
	        return Float.parseFloat(is());
	    }

	    double id() {
	        return Double.parseDouble(is());
	    }

	    char ic() {
	        return (char) skip();
	    }

	    int[] iia(int n) {
	        int a[] = new int[n];
	        for (int i = 0; i<n; i++) a[i] = ii();
	        return a;
	    }

	    long[] ila(int n) {
	        long a[] = new long[n];
	        for (int i = 0; i <n; i++) a[i] = il();
	        return a;
	    }

	    String[] isa(int n) {
	        String a[] = new String[n];
	        for (int i = 0; i < n; i++) a[i] = is();
	        return a;
	    }

		 long mul(long a, long b) { return a * b % M; }

		/*	long div(long a, long b)
				 {
					return mul(a, pow(b, M - 2,M));

		           }
*/

	    double[][] idm(int n, int m) {
	        double a[][] = new double[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
	        return a;
	        }

	    int[][] iim(int n, int m) {
	        int a[][] = new int[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
	        return a;
          }

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

   public interface SpaceCharFilter
   {
       public boolean isSpaceChar(int ch);
   }
   public boolean isEndOfLine(int c) {
       return c == '\n' || c == '\r' || c == -1;
   }
}

}


//package code;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;
/**
 *
 * @author prabhat // use stringbuilder,TreeSet, priorityQueue, x+y=(x&y + x|y);
 */
 public class  a
   {
   public static int n,max1=100005,k,m,q,a[],a1[],mat[][],id,depth[],parent[][],len=22,tin[],tout[],count=0,size[];
   public static Point[] p1,p2,p;
   public static long mod=(long)1e9+7,nCr[][],suf[][],ans=Long.MAX_VALUE,max=Long.MIN_VALUE,dp[][];
   public static boolean isPrime[],visit[],valid[][];
   public static HashSet<Integer> hash;

   public static  ArrayList<Integer> divisor[],prime,adj[],lpf;
   public static ArrayList<Character> list[];
   public static  TreeSet<Integer> ts;
   public static String s;
   public  static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   static PrintWriter pw;
   static int[] x={0,1},y={1,0};

   public static void main(String[] args) {
	new Thread(null,null,"Prabhat Kumar",99999999)
	{
	   public void run()
	   {
		   try
		   {
			   solve();
		   }
		   catch(Exception e)
		   {
			   e.printStackTrace();
			   System.exit(1);
		   }
	   }
	}.start();
}
static void solve() throws IOException
 {
	InputReader in = new InputReader(System.in);
	pw=new PrintWriter(System.out);
	n=in.ii();
	long s=in.il();
	long[] a=in.ila(n);
	Arrays.sort(a);
	long min=a[0];
	long sum=0;
	long sum1=a[0];
	for(int i=1;i<n;i++)
	{
	  sum+=a[i]-min;
	  sum1+=a[i];
	}
	if(sum>=s)pw.println(min);
	else if(sum1<s)pw.println(-1);
	else{
		long x=s-sum;
		pw.println(min-x);
	}
	pw.close();
 }
static void dfs1(int cur,int par,TreeSet<Integer> ts)
{
	if(visit[cur])return;
	visit[cur]=true;
	ts.add(cur);
	for(int ver:adj[cur])
	{
		if(visit[ver])continue;
		if(ver!=par)dfs1(ver,cur,ts);
	}
}
 static int palin(String s)
 {
	String s1=new StringBuilder(s).reverse().toString();
	return s1.equals(s)==true?1:0;
 }
 static int dfs(int u, int p) {

	//discover[count1++]=arr[u];  //  it storing color or arr of vertex u
	//discover[count1++]=u;
	//tin[u] = count++;
   int d1=1000000;
   int d2=1000000;
   int cnt=0;
	//parent[u][0] = p==-1?0:p;
	//size[u]++;
	//for (int i = 1; i < len; i++)
	//	parent[u][i] = parent[parent[u][i-1]][i-1];
	for (int v :adj[u])
		if (v != p)
		{
			cnt++;
			depth[v] = depth[u] + 1;
			int y=dfs( v, u);
			if(y<d1)
			{
				d2=d1;
				d1=y;
			}
			else if(y<d2)
			{
				d2=y;
			}
	//		size[u] += size[v];
		}
	if(cnt==0)return 1;
	ans=Math.min(d1+d2,ans);
	return 1+Math.min(d1,d2);
//	if(adj[u].size()==1&&parent[u][0]!=0)last.add(u);
//	tout[u] = count-1;
}

static boolean isParent(int parent, int child) {
	return tin[parent] <= tin[child] && tout[child] <= tout[parent];
}

static int lca(int a, int b) {
	if (isParent(a, b))
		return a;
	if (isParent(b, a))
		return b;
	for (int i = len - 1; i >= 0; i--)
		if (!isParent(parent[a][i], b))
			a = parent[a][i];
	return parent[a][0];
}
static boolean valid(int i,int j)
{
	return i>=1&&i<=n&&j>=1&&j<=m;
}

static int gcd(int a,int b)
{
	while(a!=0)
	{
		int temp=a;
		a=b%a;
		b=temp;
	}
	return b;
}
static void Seive()
{
	a1=new int[max1];
	isPrime=new boolean[max1];
	Arrays.fill(isPrime,true);
//	prime=new ArrayList<>();
//	divisor=new ArrayList[max1];
//	for(int i=1;i<max1;i++)divisor[i]=new ArrayList<Integer>();
    isPrime[0]=isPrime[1]=false;
	for(int i=2;i<(max1);i++)
	{
         if(isPrime[i]){
		//	 divisor[i].add(i);
		//	 prime.add(i);
			 a1[i]=1;
			for(int j=2*i;j<max1;j+=i)
			{
				a1[j]++;
				isPrime[j]=false;
				//divisor[j].add(i);
			}
		}
	}
}
public static long pow(long n,long p)
{
	 long  result = 1;
	  if(p==0)
	    return 1;

	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;

	    p >>=1;
	    n*=n;
	}
	return result;
}

static  class InputReader
{
   private InputStream stream;
   private byte[] buf = new byte[1024];

   private SpaceCharFilter filter;
    byte inbuffer[] = new byte[1024];
   int lenbuffer = 0, ptrbuffer = 0;
    final int M = (int) 1e9 + 7;
   int md=(int)(1e7+1);
    int[] SMP=new int[md];
   final double eps = 1e-6;
   final double pi = Math.PI;

	PrintWriter out;
   String check = "";
 InputStream   obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
   public InputReader(InputStream stream)
   {
       this.stream = stream;
   }

    int readByte() {
	        if (lenbuffer == -1) throw new InputMismatchException();
	        if (ptrbuffer >= lenbuffer) {
	            ptrbuffer = 0;
	            try {
	                lenbuffer = obj.read(inbuffer);
	            } catch (IOException e) {
	                throw new InputMismatchException();
	            }
	        }
	        if (lenbuffer <= 0) return -1;
	        return inbuffer[ptrbuffer++];
   }

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

   String is() {
	        int b = skip();
	        StringBuilder sb = new StringBuilder();
	        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
	        {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
   }
   public   int ii() {
	        int num = 0, b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }
 public   long il() {
	        long num = 0;
	        int b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }

	    boolean isSpaceChar(int c) {
	        return (!(c >= 33 && c <= 126));
	       }

	      int skip()
	        {
	        int b;
	        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
	        return b;
	        }

	    float nf() {
	        return Float.parseFloat(is());
	    }

	    double id() {
	        return Double.parseDouble(is());
	    }

	    char ic() {
	        return (char) skip();
	    }

	    int[] iia(int n) {
	        int a[] = new int[n];
	        for (int i = 0; i<n; i++) a[i] = ii();
	        return a;
	    }

	    long[] ila(int n) {
	        long a[] = new long[n];
	        for (int i = 0; i <n; i++) a[i] = il();
	        return a;
	    }

	    String[] isa(int n) {
	        String a[] = new String[n];
	        for (int i = 0; i < n; i++) a[i] = is();
	        return a;
	    }

		 long mul(long a, long b) { return a * b % M; }

		/*	long div(long a, long b)
				 {
					return mul(a, pow(b, M - 2,M));

		           }
*/

	    double[][] idm(int n, int m) {
	        double a[][] = new double[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
	        return a;
	        }

	    int[][] iim(int n, int m) {
	        int a[][] = new int[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
	        return a;
          }

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

   public interface SpaceCharFilter
   {
       public boolean isSpaceChar(int ch);
   }
   public boolean isEndOfLine(int c) {
       return c == '\n' || c == '\r' || c == -1;
   }
}

}


import java.util.*;
import java.io.*;

public class Main {
    private static long minLevel(long[] volumes, long capacity) {
        int n = volumes.length;

        long sum = 0;
        int min = 0;
        for (int i = 0; i < n; i++) {
            sum += volumes[i];
            if (volumes[i] < volumes[min])
                min = i;
        }

        if (sum < capacity)
            return -1;

        sum = 0;
        for (int i = 0; i < n; i++) {
            long cut = volumes[i] - volumes[min];
            sum += cut;
        }
        if (sum > capacity)
            return volumes[min];

        long remain = (capacity - sum);
        volumes[min] -=  remain / n;
        remain = remain % n;

        return remain != 0 ? volumes[min] - 1 : volumes[min];
    }

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long capacity = in.nextLong();
        long[] volumes = new long[n];

        for (int i = 0; i < n; i++) {
            volumes[i] = in.nextLong();
        }
        System.out.println(minLevel(volumes, capacity));
        in.close();
	}
}


import java.util.*;
import java.io.*;

public class Main {
    private static long minLevel(long[] volumes, long capacity) {
        int n = volumes.length;

        long sum = 0;
        int min = 0;
        for (int i = 0; i < n; i++) {
            sum += volumes[i];
            if (volumes[i] < volumes[min])
                min = i;
        }

        if (sum < capacity)
            return -1;

        for (int i = 0; i < n; i++) {
            long cut = volumes[i] - volumes[min];
            if (capacity - cut < 0)
                break;
            capacity -= cut;
        }

        volumes[min] -= (capacity / n);
        return capacity % n != 0 ? --volumes[min] : volumes[min];
    }

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        long capacity = in.nextLong();
        long[] volumes = new long[n];

        for (int i = 0; i < n; i++) {
            volumes[i] = in.nextLong();
        }
        System.out.println(minLevel(volumes, capacity));
        in.close();
	}
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        long capacity = in.nextInt();
        long[] volume = new long[n];

        long sum = 0;
        for (int i = 0; i < n; i++) {
            volume[i] = in.nextLong();
            sum += volume[i];
        }

        if (sum < capacity) {
            System.out.println(-1);
            return;
        }

        Arrays.sort(volume);

        for (int i = 1; i < n; i++) {
            long cut = volume[i] - volume[0];
            volume[i] -= cut;
            capacity -= cut;
        }

        for (int i = 0; i < n; i++) {
            volume[i] -= (capacity / n);
        }
        System.out.println(volume[0] - ((capacity % n) != 0 ? 1 : 0));

        in.close();
	}
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        long capacity = in.nextLong();
        long[] volume = new long[n];

        long sum = 0;
        for (int i = 0; i < n; i++) {
            volume[i] = in.nextLong();
            sum += volume[i];
        }

        if (sum < capacity) {
            System.out.println(-1);
            return;
        }

        Arrays.sort(volume);

        for (int i = 1; i < n; i++) {
            long cut = volume[i] - volume[0];
            volume[i] -= cut;
            capacity -= cut;
        }

        for (int i = 0; i < n; i++) {
            volume[i] -= (capacity / n);
        }
        System.out.println(volume[0] - ((capacity % n) != 0 ? 1 : 0));

        in.close();
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
//import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.*;
public class PJ  {
    static HashMap<Long,Long> hs;

    public static void main(String[] args) throws Exception
    {
    	StringTokenizer st ;
    	Scanner sc = new Scanner(System.in);
    	boolean file = false;
		BufferedReader br =!file?new BufferedReader(new InputStreamReader(System.in)):new BufferedReader(new FileReader("leaves.in"));
		PrintWriter out  = new PrintWriter(System.out);
		st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());long s = Long.parseLong(st.nextToken());
		st = new StringTokenizer(br.readLine());
		long[] arr = new long[n];
		long min = Long.MAX_VALUE;
		for(int i=0;i<n;i++)
		{
			arr[i] = Long.parseLong(st.nextToken());
			min= (long) Math.min(min, arr[i]);
		}
		for(int i=0;i<n;i++)
			s -= arr[i]-min;
		min-= s/(long)n;
		if(s-s/(long)n > 0)
			min--;
		out.println(min>=0?min : -1);

		out.flush();
		out.close();
    }

    static boolean plus(char c)
    {
    	return c=='+';
    }
    static int log(int x, int base)
    {
        return (int) (Math.log(x) / Math.log(base));
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
//import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.*;
public class PJ  {
    static HashMap<Long,Long> hs;

    public static void main(String[] args) throws Exception
    {
    	StringTokenizer st ;
    	Scanner sc = new Scanner(System.in);
    	boolean file = false;
		BufferedReader br =!file?new BufferedReader(new InputStreamReader(System.in)):new BufferedReader(new FileReader("leaves.in"));
		PrintWriter out  = new PrintWriter(System.out);
		st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());long s = Long.parseLong(st.nextToken());
		st = new StringTokenizer(br.readLine());
		int[] arr = new int[n];
		int min = Integer.MAX_VALUE;
		for(int i=0;i<n;i++)
		{
			arr[i] = Integer.parseInt(st.nextToken());
			min=Math.min(min, arr[i]);
		}
		for(int i=0;i<n;i++)
			s -= arr[i]-min;

		while(s>0)
		{
			s-=n;min--;
		}
		out.println(min>=0?min:-1);
		out.flush();
		out.close();
    }

    static boolean plus(char c)
    {
    	return c=='+';
    }
    static int log(int x, int base)
    {
        return (int) (Math.log(x) / Math.log(base));
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
//import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.*;
public class PJ  {
    static HashMap<Long,Long> hs;

    public static void main(String[] args) throws Exception
    {
    	StringTokenizer st ;
    	Scanner sc = new Scanner(System.in);
    	boolean file = false;
		BufferedReader br =!file?new BufferedReader(new InputStreamReader(System.in)):new BufferedReader(new FileReader("leaves.in"));
		PrintWriter out  = new PrintWriter(System.out);
		st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());long s = Long.parseLong(st.nextToken());
		st = new StringTokenizer(br.readLine());
		long[] arr = new long[n];
		long min = Long.MAX_VALUE;
		for(int i=0;i<n;i++)
		{
			arr[i] = Long.parseLong(st.nextToken());
			min= (long) Math.min(min, arr[i]);
		}
		for(int i=0;i<n;i++)
			s -= arr[i]-min;
		min-= s/(long)n;
		if(s-(long)n*(s/(long)n) > 0)
			min--;
		out.println(min>=0?min : -1);

		out.flush();
		out.close();
    }

    static boolean plus(char c)
    {
    	return c=='+';
    }
    static int log(int x, int base)
    {
        return (int) (Math.log(x) / Math.log(base));
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
//import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.*;
public class PJ  {
    static HashMap<Long,Long> hs;

    public static void main(String[] args) throws Exception
    {
    	StringTokenizer st ;
    	Scanner sc = new Scanner(System.in);
    	boolean file = false;
		BufferedReader br =!file?new BufferedReader(new InputStreamReader(System.in)):new BufferedReader(new FileReader("leaves.in"));
		PrintWriter out  = new PrintWriter(System.out);
		st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());long s = Long.parseLong(st.nextToken());
		st = new StringTokenizer(br.readLine());
		int[] arr = new int[n];
		int min = Integer.MAX_VALUE;
		for(int i=0;i<n;i++)
		{
			arr[i] = Integer.parseInt(st.nextToken());
			min=Math.min(min, arr[i]);
		}
		for(int i=0;i<n;i++)
			s -= arr[i]-min;

		while(s>0 && min>=0)
		{
			s-=n;min--;
		}
		out.println(min>=0?min:-1);
		out.flush();
		out.close();
    }

    static boolean plus(char c)
    {
    	return c=='+';
    }
    static int log(int x, int base)
    {
        return (int) (Math.log(x) / Math.log(base));
    }
}