The only difference between easy and hard versions is the constraints.Polycarp has to write a coursework. The coursework consists of $$$m$$$ pages.Polycarp also has $$$n$$$ cups of coffee. The coffee in the $$$i$$$-th cup has $$$a_i$$$ caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.Let's consider some day of Polycarp's work. Consider Polycarp drinks $$$k$$$ cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are $$$a_{i_1}, a_{i_2}, \dots, a_{i_k}$$$. Then the first cup he drinks gives him energy to write $$$a_{i_1}$$$ pages of coursework, the second cup gives him energy to write $$$max(0, a_{i_2} - 1)$$$ pages, the third cup gives him energy to write $$$max(0, a_{i_3} - 2)$$$ pages, ..., the $$$k$$$-th cup gives him energy to write $$$max(0, a_{i_k} - k + 1)$$$ pages.If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 10^4$$$) — the number of cups of coffee and the number of pages in the coursework. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the caffeine dosage of coffee in the $$$i$$$-th cup.

If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.

NoteIn the first example Polycarp can drink fourth cup during first day (and write $$$1$$$ page), first and second cups during second day (and write $$$2 + (3 - 1) = 4$$$ pages), fifth cup during the third day (and write $$$2$$$ pages) and third cup during the fourth day (and write $$$1$$$ page) so the answer is $$$4$$$. It is obvious that there is no way to write the coursework in three or less days in this test.In the second example Polycarp can drink third, fourth and second cups during first day (and write $$$4 + (2 - 1) + (3 - 2) = 6$$$ pages) and sixth cup during second day (and write $$$4$$$ pages) so the answer is $$$2$$$. It is obvious that Polycarp cannot write the whole coursework in one day in this test.In the third example Polycarp can drink all cups of coffee during first day and write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15$$$ pages of coursework.In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) = 14$$$ pages of coursework and during second day he will write $$$5$$$ pages of coursework. This is enough to complete it.In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.

#include <bits/stdc++.h>
using namespace std;
long long arr[200003],n,m,sum,bs,l = 1, r = 200000,ans=0LL;
bool chk(long long d)
{
    long long ret=0;
    for(long long i=0;i<n;i++) ret+=max(0LL,(arr[i]-i/d));
    return ret>=m;
}
int main()
{
    scanf("%lld %lld",&n,&m);
    for(long long i=0;i<n;i++) scanf("%lld",&arr[i]);
    sort(arr,arr+n); reverse(arr,arr+n);
    for(bs=0;bs<100 ;bs++)
    {
        if(l>r) break;
        if(chk((l+r)/2)) ans = (l+r)/2,r=(l+r)/2-1;
        else l=(l+r)/2+1;
    }
    if(ans) printf("%lld",ans);
    else printf("-1");
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int sum=0;
    for (int i=0;i<n;i++)
        cin>>a[i],sum+=a[i];
    if (sum<m)
    {
        cout<<-1;
        exit(0);
    }
    sort(a,a+n);
//    for (int i=0;i<n;i++)
    //    cout<<a[i]<<" ";
  //  cout<<endl;
    for (int i=1;i<=n;i++)
    {
        int chk=0;
        for (int j=n-1;j>=0;j--)
        {
            chk+=max(0,a[j]-(n-1-j)/i);
            if (max(0,a[j]-(n-1-j)/i)==0)
                break;
//            cout<<chk<<endl;
            if (chk>=m)
                break;
        }
  //      cout<<endl;
//        cout<<chk<<endl;
        if (chk>=m)
        {
            cout<<i;
            exit(0);
        }
    }
}

//#define _CRT_SECURE_NO_WARNINGS
//             ÈÓã ÇáËÇáæË ÇáÇÞÏÓ

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<iomanip>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<fstream>
#include<bitset>
#include <cstring>
using namespace std;
const double EPS = 1e-8;
//jesus help me.......
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
bool sortby(const pair<int, int>&a, const pair<int, int>&b)
{
	if (a.first >= b.first&&a.second >= b.second)
		return true;
	return false;
}
//////////////////////////////////////////////////
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	return abs((x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)) / 2.0);
}
//////////////////////////////////////////////////
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int arr[1005];
int ans[21][21];
/////////////////////////////////////////////////
int main()
{
	fast();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//cout << gcd(15, 10);
	int n, m;
	cin >> n >> m;
	vector<int>v(n);
	for (int i = 0;i < n;i++)
	{
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	bool b = false;
	for (int i = 1;i <= n;i++)
	{
		int k = m;
		int j = 0;
		for (int h = 1;h <= i;h++)
		{
			k -= v[j++];
		}
		int g = 1,h=1;
		while (j < n&&(v[j]-g)>0)
		{
			k -= (v[j] - g);
			h++;
			if (h > i)
			{
				h = 1;
				g++;
			}
			j++;
		}
		if (k <= 0)
		{
			cout << i << endl;
	//			system("pause");
			return 0;
		}
	}
	cout << -1 << endl;
	//	system("pause");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<int,int>pii;
typedef pair<int,pair<int,int>>piii;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define sf(a) scanf("%I64d",&a)
#define pf(a) printf("%I64d\n",a)
#define mem(a,b)     memset(a,b,sizeof(a))
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define F first
#define S second
#define minheap int,vector<int>,greater<int>
//#define mp make_pair
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)
        return 0;

    return a/__gcd(a,b)*b;
}
//___________________________________________________________________________________________________________________
//                              CODE STARTS FROM HERE
//                               MU_Codefighter2019
//-------------------------------------------------------------------------------------------------------------------

void inputa(ll ara[],ll n)
{
    ull sum=0;

    for(int i=0; i<n; i++)
        cin>>ara[i];
}
int main()
{
    fastread();

      ll n,m,extra=0,cnt=0,j,k;

      cin>>n>>m;

      ll ara[n+1],i,sum=0;

      for(i=0; i<n; i++)
      {
          cin>>ara[i];

          sum+=ara[i];
      }

      if(sum<m)cout<<-1<<endl;

      else
      {
          sort(ara,ara+n,greater<ll>());

          for(i=1; i<=n; i++)
          {
              sum=0;

              for(j=0; j<n; j++)
              {

                  sum+=max(ara[j]-j/i,0ll);

                  //cout<<j/i<<" ";
              }

              //cout<<endl;

             // cout<<sum<<endl;

              if(sum>=m)
              {
                  cout<<i<<endl;

                  return 0;
              }
          }

          cout<<-1<<endl;
      }

}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define INF LONG_LONG_MAX

using namespace std;

int main(void)
{
	ll n, m, sum=0;
	cin >> n >> m;
	vector<ll> a(n), asum;
	vector<vector<ll>> dp(n+1, vector<ll>(m+1));
	rep(i, n){
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	asum.push_back(0);
	rep(i, n){
		asum.push_back(asum.back()+a[i]);
	}
	if (asum[n] < m){
		cout << -1 << endl;
		return 0;
	}
	//DP構成
	for(ll i=n; i>=0; i--){
		ll border = asum[n]-asum[i];
		for(ll j=0; j<=m; j++){
			if (j>border){
				dp[i][j] = INF;
			}else if(j==border){
				dp[i][j] = n-i;
			}else if(j == 0){
				dp[i][j] = 0;
			}else{
				ll mini = INF;
				ll k = i, p = j, l = 0;
				while(k<n && a[k]-l>=0){
					ll temp;
					p -= a[k++]-l;
					temp = max(0LL, p);
					if (temp == INF) break;
					mini = min(mini, dp[k][temp]);
					l++;
				}
				dp[i][j] = mini+1;
			}
		}
	}
	cout << dp[0][m] << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ff                  first
#define ss                  second
#define MAX                 200005
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 10000000
#define inf                 LONG_MAX
#define PI                  acos(-1.0)  // 3.1415926535897932
typedef long long int ll;
typedef long double lld;
using namespace std;

int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    int ara[n+5],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
        sum+=ara[i];
    }
    sort(ara,ara+n);
    reverse(ara,ara+n);
   // for(int i=1;i<=n;i++)cout<<ara[i]<<endl;
    if(sum<k)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int ans=n;
    for(int j=1;j<=n;j++)
    {
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=max(0,ara[i]-(i/j));
        }
        if(sum>=k)
        {
            ans=min(ans,j);
        }
    }
    cout<<ans<<endl;
}

#include<cstdio>
#include<algorithm>
#include<windows.h>
#include<cstring>
using namespace std;

int n,m;
long long a[(int)2e5+5];
long long sum;
long long cnt;
bool cmp(int x,int y){
return x>y;
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    if(sum<m)
    printf("-1");
    else{
    sort(a+1,a+n+1,cmp);
    int l=1;
    int r=n;
    int mid=0;
    while(l<=r){
    mid=(l+r)/2;
     sum=0;
     cnt=0;
    for(int i=1;i<=n;i++){
       cnt=(i-1)/mid;
       if(a[i]<=cnt)
       break;
       sum+=a[i]-cnt;
    }
    if(sum<m)
    l=mid+1;
    else if(sum>m)
    r=mid-1;
    else
    break;
    //printf("%d %d\n",mid,sum);
    }
     sum=0;
     cnt=0;
     for(int i=1;i<=n;i++){
       cnt=(i-1)/mid;
       if(a[i]<=cnt)
       break;
       sum+=a[i]-cnt;
    }
    if(sum>=m)
    printf("%d",mid);
    else
    printf("%d",mid+1);
    }
    //system("pause");
    return 0;
}
/*
5 8
2 3 1 1 2

4
*/

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int n, m;
int a[200100];
bool cmp(int x, int y)
{
	return x>y;
}
bool check(int x)
{
	if(x<=0)return false;
	ll cnt = 0;
	for(int i = 0;i < n; i++)
	{
		cnt += max(a[i] - i/x, 0);
	}
	return cnt>=m;
}
int main()
{
	while(cin>>n>>m)
	{
		for(int i = 0;i < n; i++)
		{
			cin>>a[i];
		}
		sort(a, a+n, cmp);
		int l = 0, r = 1e9+10, ans = 0;
		while(l<r)
		{
			int mid = (l+r)>>1;
			if(check(mid))
			{
				ans = mid;
				r = mid;
			}
			else
			{
				l = mid+1;
			}
		}
		if(l!=1e9+10)
			cout<<ans<<endl;
		else
			cout<<"-1"<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int compare(int a, int b) { return a > b; }
signed main() {
        ios :: sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        int n, m; cin >> n >> m;
        int arr[n + 1];
        int total = 0;
        for (int i = 1; i <= n; i++) {
                cin >> arr[i];
                total += arr[i];
        }
        if (total < m) {
                cout << -1 << endl;
                return 0;
        }
        sort(arr + 1, arr + n + 1, compare);
        int l = 1, r = n, ans = 0;
        int g = 0;
        while(l <= r) {
                int mid = (l + r) / 2;
                int res = 0;
                bool f = false;
                for (int i = 1; i <= mid; i++) {
                        for (int j = i, h = 0; j <= n; j += mid, h++) {
                        if (g > 25) return 0;
                                if ((arr[j] - h) > 0) {
                                        res += (arr[j] - h);
                                        if (res >= m) {
                                                f = true;
                                                break;
                                        }
                                }
                        }
                        if (f) break;
                }
                if (f) {
                       ans = mid;
                       r = mid - 1;
                } else {
                       l = mid + 1;
                }
        }
        cout << ans << endl;
        return 0;
}

#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> a;

bool can(int i) {
	long long sum = 0; // there can be a bug
	for (int j = 0; j < n; ++j) {
		sum += max(a[j] - j / i, 0);
	}
	return sum >= m;
}

int main() {

	cin >> n >> m;

	a = vector<int>(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());

	int l = 1, r = n;
	int best=-1;
	while (l<=r) {
		int mid = (l + r) >> 1;
		if (can(mid)) r = mid-1,best=mid;
		else l = mid+1;
	}

	printf("%d\n",best);

	return 0;
}

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
#define MAX 200
int n, m, ans;
int a[MAX];
vector<int> V[MAX];
bool check(int day) {
	int all = m;
	int tot = 0;
	for (int i = 1; i <= n; i++) {
		if ((tot += max(0, a[i] - (i - 1) / day)) >= m)
			return true;
	}
	return false;
}

int main() {
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	bool f = false;
	sort(a + 1, a + 1 + n);
	reverse(a + 1, a + 1 + n);
	int l = 1, r = n, mid;
	while (l < r) {
		mid = (l + r) >> 1;
		if (check(mid)) {
			r = mid;
		}
		else {
			l = mid + 1;
		}
	}
	if (l == n) {
		if (sum >= m)
			f = true;
	}
	else {
		f = true;
	}

	if (!f)
		cout << -1 << endl;
	else
		cout << l << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define dbl long double
#define mod 998244353
map<ll,ll> mp;
ll n,m;
ll a[105];
bool check(ll k){
    ll sum=0;
    ll u=0;
    for(ll i=0;i<n;i++){
        ll t=k;
        ll f=1;
        ll j=i;
        while(t--){
            if(a[j]-u<=0){
                f=0;
            break;
            }
            sum+=max(a[j]-u,(ll)0);
           j++;
        }
        i=j-1;
        u++;
        if(sum>=m){
            return true;
        }
        if(!f)
        break;
    }
    return false;
}

int main(){
//ll n,m;
cin>>n>>m;
for(ll i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
reverse(a,a+n);
ll l=1;
ll h=n;
ll ans=n+1;
while(l<=h){
    ll m=(l+h)/2;
    if(check(m)){
        ans=m;
        h=m-1;
    }
    else
    l=m+1;
}
if(ans<=n){
    cout<<ans;
}
else
cout<<"-1";
}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define endl "\n"
int n;

int check(int *a, int day, int key) {
    int cnt = 0;
    for (int i=0; i<n; i++) {
        cnt += max(0, a[i]-i/day);
    }
    if (cnt >= key)
        return 1;
    else
        return -1;
}

int search(int *a, int low, int high, int key) {
    int ans = -1;
    while(low <= high) {
        int mid = low + (high - low + 1) / 2;
        int day = check(a, mid, key);
        //cout << mid << " " << day << endl;
        if (day == -1) {
            low = mid + 1;
        }
        else {
            ans = mid;
            high = mid - 1;
        }
    }
    return ans;
}

void testCase() {
    int m;
    cin >> n >> m;
    int a[n+1];
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a+n);
    reverse(a, a+n);
   // int ans = search(a, 1, n, m);
    /*int ans = -1;
    for (int i=1; i<=n; i++) {
        int ans = check(a, i, m);
        cout << ans << endl;
    }*/
    int ans = search(a, 1, n, m);
    cout << ans << endl;
    //cout << ans << endl;
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long int ll;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vs;

#define FOR(i, a, n) for (int i = (a); a<n? i<n:i>n; a<n? i++:i--)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define clr(x) memset(x, 0, sizeof(x))
#define pb push_back
#define f first
#define s second
#define lli ll
#define bhag_milkha ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<"\n";}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t";
	err(++it, args...);
}

const int MOD = 1000000007;
const int N = 2e5;

// ll mpow(ll base, ll exp)
// {
//         base %= MOD;
//         int result = 1;
//         while (exp > 0) {
//         if (exp & 1) result = ((ll)result * base) % MOD;
//         base = ((ll)base * base) % MOD;
//         exp >>= 1;
//       }
//       return result;
// }

// vi graph[N];
// void readGraph(ll m)
// {
//         int u,v;
//         FOR(i,0,m)
//         {
//             cin>>u>>v;
//             u--,v--;
//             graph[u].pb(v),graph[v].pb(u);
//         }
// }

// prefer global arrays over ordered/unordered maps.
// prefer ordered maps over unordered if time constraints allow.
// clear global data if multiple test cases are there.
// avoid passing big objects like arrays/vectors to a function.

int a[101];
int dp[101][101];

int main()
{
        bhag_milkha
        int n,m; cin>>n>>m;
        FOR(i,1,n+1) cin>>a[i];
        sort(a+1,a+n+1,greater<int>());
        int ans = INT_MAX;
        FOR(i,1,n+1)
        {
                FOR(j,1,i+1)
                {
                        int sum = 0;
                        FOR(k,i,0)
                        {
                                sum += a[k]-(i-k);
                                dp[i][j] = max(dp[i][j],dp[k-1][j-1]+sum);
                        }
                        if(dp[i][j] >= m) ans = min(ans,j);
                }
        }
        if(ans==INT_MAX) ans = -1;
        cout<<ans;
        return 0;
}

#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<random>
#include<bitset>
#include<complex>
#include<cassert>
#include<sstream>
#include<set>

#define int long long int

using namespace std;

int n, m;
vector<int> a;

bool check(int mid){
    int summ = 0;
    for(int i = 0; i < n; i++){
        summ += max(0ll, a[i] - (i / mid));
    }
    return summ >= m;
}

signed main(){
    cin >> n >> m;
    a.resize(n);
    int s = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }
    if(s < m){
        cout << -1 << "\n";
        return 0;
    }
    sort(a.rbegin(), a.rend());
    int l = 0, r = n;
    while(r - l > 1){
        int mid = (l + r) / 2;
        if(check(mid))r = mid;
        else l = mid;
    }
    cout << r << "\n";
    return 0;
}

    #include <bits/stdc++.h>
    using namespace std;
    #define f(i,n) for(i=0;i<n;i++)

    void d()
    {
        //specially made for debuggin
        cout <<"hello";
    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);

   //   freopen("input.txt","r",stdin);

    int i,j,n,m;
    int p,q;
    cin >> n >> m;

    int a[n];
    int sum=0;
    int ans=10001;
    f(i,n) {  cin >> a[i]; sum+=a[i]; }

    sort(a,a+n);

   f(i,n)
    {

    if(sum < m) break;
    f(j,n-i)
    {
        q=j+1;
        p=n-i-q;

     if(sum- q*((p/q)*(p/q+1))/2-(p%q)*(p/q+1) >=m) ans=min(ans,q);

    }
    sum-=a[i];
    }

if(ans==10001) cout <<"-1";
else cout << ans;
        return 0;
    }

#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

ll gcd(ll a,ll b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
ll mod=1e9+7;
ll mod1=1e9+6;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod,b/2);
    else return a*power(a*a%mod,b/2)%mod;
}
ll power1(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod1,b/2);
    else return a*power(a*a%mod1,b/2)%mod1;
}
void show(vector <pair<int,int>> v)
{
    for(int i=0;i<v.size();++i) cout<<v[i].first<<" "<<v[i].second<<" ";
        cout<<endl;
}
bool check(string s,int n)
{

        for(int i=0;i<n/2;++i)
        {
            if(s[i]==s[n-1-i]);
            else return false;
        }
        return true;

}
ll sum(ll x)
{ll z,y=0;
 if(x/10==0)
    return x;
 else{
    for(ll i=x;i>0;i=i/10)
    {
        z=i%10;
        y=y+z;
    }
    return sum(y);
 }
}
int main()
{
    IOS
    int n,m;
    cin>>n>>m;

    int a[n];
    ll sum=0;
    for(int i=0;i<n;++i) { cin>>a[i];sum=sum+a[i];}
        if(n==1)
        {
            if(a[0]>=m) cout<<1<<endl;
            return 0;

        }
        if(sum<m)
        {
            cout<<-1;

        }
        else if(sum==m)
        {
            cout<<n<<endl;
        }
        else
        {
            sort(a,a+n,greater<int>());
            ll sum1[n+1];
            sum1[0]=0;
            for(int i=0;i<n;++i)
                sum1[i+1]=a[i]+sum1[i];
            ll t;
            int start=1,end=n;
            while(start<end){ //t=sum;
               int mid=(start+end)/2;
               int l=0;
                for(int j=mid+1;j<=n;++j){
                t=sum1[j];
                ll p=(j-mid)/mid;
                ll s=mid*p*(p+1)/2;

                ll k=(j-mid)%mid;
                t=t-s-k*(p+1);
                if(t>=m)
                {
                    end=mid;
                    l=1;
                    break;
                    //cout<<mid;
                    //return 0;
                }

            }
            if(l==0)
            start=mid+1;
        //if(start>end) break;

        }
        cout<<start;

}
}

#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b)
{
    if (a > b)
        return 1;
    else
        return 0;
}
int main()
{
    int n, m, cnt = 0;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt += a[i];
    sort(a.begin(), a.end(), cmp);
    if (cnt < m)
        cout << -1;
    else
    {
        int right = n, left = 0;
        while (abs(right - left) > 1)
        {
            int mid = (left + right) / 2;
            int ans = 0;
            for (int i = 0; i < n; ++i)
                ans += max(0, a[i] - (int)i / mid);
            if (ans >= m)
                right = mid;
            else
                left = mid;
        }
        cout << right;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define show(x) cout<<x<<endl;
#define showEnd(x)   cout<<x<<endl,exit(0);
#define show_(x)    cout<<x<<" ";
#define showxy(x,y) cout<<x<<" "<<y<<endl;
typedef long long ll;
const int maxn = 105;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;

int i,j,n,m,a[maxn],sum = 0;

bool cmp(const int x, const int y)
{
    return x > y;
}

int main()
{
    IO
    cin>>n>>m;
    for(i = 1; i <= n; i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    if(sum < m)     showEnd(-1)
    if(sum == m)    showEnd(n)
    sort(a+1, a+n+1,cmp);
    for(i = 1; i <= n; i++)
    {
        int temp = 0;
        for(j = 1; j <= n; j++)
        {
            temp += max(0, a[j]-(j-1)/i);
            if(temp >= m)   showEnd(i);
        }
    }
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
using namespace std;
ll int n,m;
ll int a[200005];
void solve(){
	cin>>n>>m;
	int sum=0;
	rep(i,n){cin>>a[i];sum+=a[i];}
	if(sum<m){
		cout<<-1;
		return ;
	}
	int low=1,high=n;
	sort(a,a+n,greater<int>());
	/*int ps[n+1];
	ps[0]=0;
	rep(i,n)ps[i]=ps[i-1]+a[i];*/
	while(low<high){
		ll int mid=low+(high-low)/2;
		ll int x=0;
		int i=0;
		while(i<n){
			x=x+max(0LL,(a[i]-(i/mid)));
			i++;
		}
		//cout<<mid<<" "<<x<<"\n";
		if(x>=m)high=mid;
		else low=mid+1;
	}
	cout<<low;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

#include <iostream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <map>

using namespace std;

int solve(vector<int> & nums, int m)
{
    int n = nums.size();

    sort(nums.rbegin(), nums.rend());

    for(int i=1; i<=n; i++)
    {
        int sum = 0;
        for(int j=0; j<n; j++)
        {
            sum += max(0, nums[j] - (j/i));
        }

        if(sum>=m)
        {
            return i;
        }
    }

    return -1;
}

int main()
{
    int n;
    int m;

    cin >> n >> m;

    vector<int> nums(n);
    for(int i=0; i<n; i++)
    {
        cin>>nums[i];
    }

    int result = solve(nums, m);

    cout<<result<<endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 105;

int n, m, a[N], csum[N], dp[N][10005];

int fun(int pos, int baki) {
  if (pos > n) {
    return baki <= 0 ? 0 : 1e9;
  }
  if (baki <= 0) {
    return 0;
  }
  int &tmp = dp[pos][baki];
  if (tmp != -1) {
    return tmp;
  }
  tmp = 1e9;
  for (int i = 1; i <= n - pos + 1; i++) {
    int reduce = csum[pos + i - 1] - csum[pos - 1] - (i * (i - 1) / 2);
    tmp = min(tmp, 1 + fun(pos + i, baki - reduce));
  }
  tmp = min(tmp, fun(pos + 1, baki));
  return tmp;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 1; i <= n; i++) {
    csum[i] += a[i] + csum[i - 1];
  }
  memset(dp, -1, sizeof dp);
  int ans = fun(1, m);
  if (ans == 1e9) {
    cout << -1 << '\n';
  } else {
    cout << ans << '\n';
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <iomanip>
#include <set>
#include <deque>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
using namespace std;

const int N = 2e6 + 100, PI = 3.14159265359 , M = 1e9 + 7;
typedef pair <ll, ll> pii;
ll a[N], p[N];
ll n, m;

bool cheek(ll x) {
 ll y = 0;
 for(int i = n; i >= 1; i--) {
  y += max((ll)0, a[i] - ((n - i) / x));

 }
 return (y >= m);
}

int main() {
 cin >> n >> m;
 for(int i = 1; i <= n; i++) {
  cin >> a[i];
 }
 sort(a + 1, a + n + 1);
 ll r = n, l = 0;
 while(r - l > 1) {
  ll mid = (l + r) / 2;
  if(cheek(mid) == true) {
   r= mid;
  }
  else
   l = mid;
 }
 if(cheek(r) == false) {
  cout << -1;
  return 0;
 }
 cout << r;
 return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    int c;
    cin>>c;

  int b[a];
//  int z=0,x=0;
for(int i=0;i<a;i++)
cin>>b[i];

sort(b,b+a);
reverse(b,b+a);
for(int i=1;i<=a;i++){
    int z=0;

    for(int j=0;j<a;j++)
    z=z+max(b[j]-j/i,0);
    if(z>=c){
        cout<<i;
        return 0;
    }
}
cout<<-1;

}

#include<bits/stdc++.h>
using namespace std;
#define fuck(x) cout<<#x<<"  "<<x<<endl;
int a[105],prea[105],n,m;
bool cmp(int x,int y)
{
    return x>y;
}
int pro(int st,int num,int cnt)
{
    int ans=0;
    for(int i=st;i<=st+num-1;i++)
        ans+=((a[i]-cnt)>=0)?(a[i]-cnt):0;
    return ans;
}
bool check(int mid)
{
    int st=1,tmp=0,cnt=0,num;
    while(st<=n)
    {
        num=min(n-st+1,min(mid,n));
        if(a[st+num-1]>=cnt)
            tmp+=prea[st+num-1]-prea[st-1]-cnt*num;
        else
            tmp+=pro(st,num,cnt);
        if(tmp>=m) return true;
        if(a[st+num-1]<cnt) return false;
        cnt++;
        st+=num;
    }
    return false;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&(a[i]));
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++) prea[i]=prea[i-1]+a[i];
    int low=1,high=100,mid,ans=-1;
    while(low<=high)
    {
        mid=(low+high)>>1;

        if(check(mid))
            high=mid-1,ans=mid;
        else
            low=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a,a+n,greater<int>());
    for(int i=1; i<=n; i++)
    {
     int j=0,sum=0;
      while(j<n)
       {sum+=max(0,a[j]-j/i);j++;}
     if(sum>=m)
     {
         cout<<i;
         return 0;
     }
    }
    cout<<-1;
    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define INF LONG_LONG_MAX

using namespace std;

int main(void)
{
	ll n, m, sum=0;
	cin >> n >> m;
	vector<ll> a(n), asum;
	vector<vector<ll>> dp(n+1, vector<ll>(m+1));
	rep(i, n){
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	asum.push_back(0);
	rep(i, n){
		asum.push_back(asum.back()+a[i]);
	}
	if (asum[n] < m){
		cout << -1 << endl;
		return 0;
	}
	//DP構成
	for(ll i=n; i>=0; i--){
		ll border = asum[n]-asum[i];
		for(ll j=0; j<=m; j++){
			if (j>border){
				dp[i][j] = INF;
			}else if(j==border){
				dp[i][j] = n-i;
			}else if(j == 0){
				dp[i][j] = 0;
			}else{
				ll mini = INF;
				ll k = i, p = j, l = 0;
				while(k<n && a[k]-l>=0){
					p -= a[k++]-l;
					mini = min(mini, dp[k][max(0LL, p)]);
					l++;
				}
				dp[i][j] = mini+1;
			}
		}
	}
	cout << dp[0][m] << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {

	int n, m;
	cin >> n >> m;
	int t=0;

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> t;
		a.push_back(t);
	}
	sort(a.rbegin(), a.rend());

	for (int i = 1; i <= n; ++i) {
		int sum = 0;
		for (int j = 0; j < n; ++j) {
			sum += max(a[j] - j / i, 0);
		}
		if (sum >= m) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n >> m;

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());

	for (int i = 1; i <= n; ++i) {
		int sum = 0;
		for (int j = 0; j < n; ++j) {
			sum += max(a[j] - j / i, 0);
		}
		if (sum >= m) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[105],m,n,temp[105];
bool check(ll mi)
{
    ll ans=0,k=0;
    for(ll i=n;i>=1;i--)
    {
       ans+=max(0LL,arr[i]-temp[i%mi]);
       temp[i%mi]++;
       if(ans>=m)
       {
           return true;
       }
    }
    if(ans>=m) return true;
    else return false;
}
int main()
{
    scanf("%lld %lld",&n,&m);
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld",&arr[i]);
    }
    sort(arr+1,arr+n+1);
    ll lo=1,hi=n,mid=0;
    ll ans=0;
    while(lo<=hi)
    {
        memset(temp,0,sizeof temp);
        mid=(lo+hi)/2;
        ///cout<<lo<<" "<<hi<<" "<<mid<<endl;
        if(check(mid))
        {
            hi=mid-1;
            ans=mid;
        }
        else lo=mid+1;
    }
    if(ans!=0)
    cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};

bool check(ll mid,vi v,ll m){
  ll n=v.size();
  ll cnt=0;
  ll ans=0;
  for(int i=0;i<n;i++){
    ans+=max(0LL,v[i]-cnt);
    if((i+1)%mid==0)cnt++;
  }
  // cout<<mid<<" "<<ans<<endl;
  return ans>=m;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  vi v(n);
  ll sum=0;
  for(int i=0;i<n;i++){
    cin>>v[i];
    sum+=v[i];
  }
  sort(ALL(v),greater<ll>());
  if(sum<m){
    cout<<-1<<endl;
    return 0;
  }

  ll le=0,ri=n;
  while(ri-le>1){
    ll mid=(ri+le)/2;
    if(check(mid,v,m)){
      ri=mid;
    }else{
      le=mid;
    }
  }
  cout<<ri<<endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull;

int a[105];
int n,m;

bool cmp(int a,int b){
    return a>b;
}

bool erfen(int mid){
    int sum=0;
    int co=1;
    for(int i=1;i<=mid;i++) sum+=a[i];
    int i=mid+1;
    int cc=0;
    while(i<=n){
        if(a[i]-co<=0) break;
        sum+=a[i]-co;
        cc++;
        i++;
        if(cc==mid) cc=0,co++;
    }
    if(sum>=m) return true;
    return false;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    cin>>n>>m;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+n+1,cmp);
    if(m>sum){
        cout<<-1<<endl;
        return 0;
    }
    int l=1,r=n,mid;
    int ans=-1;
    while(l<=r){
        mid=l+r>>1;
        if(erfen(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

#define mkp(i,j) make_pair(i,j)
#define INF 1<<30
const int MAX=1e3+10;
typedef pair<int,int> ii;
typedef long long ll;

map<int , int > mp;
ll coffe[MAX];
int n,m;

bool cmp(ll a,ll b){return a>b;}

ll compute(int day){
    ll diff = 0;
    ll ans = 0;
    for(int i = 0;i<n;diff++){
        for(int d = 0;d<day;i++,d++){
            ans += max(ll(0),coffe[i] - diff);
        }
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin>>n>>m;

    ll sum = 0;
    for(int i = 0;i<n;i++){
        cin>>coffe[i]; sum += coffe[i];
    }
    if(sum<m) return cout<<-1<<endl, 0 ;
    sort(coffe,coffe+n,cmp);

    for(int day = 1;1;day++){
        if(compute(day)>=m) return cout<<day<<"\n" , 0 ;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,i,j,x,sum=0,c=0,a[101],k;
cin>>n>>m;
for(i=0;i<n;i++)
{
    cin>>a[i];
}
sort(a,a+n);

for(i=1;i<=n;i++)
{
    x=n-1;
    sum=0;
    for(j=1;j<=n;j++)
    {
        for(k=1;k<=i;k++)
        {
            if(x>=0)
            sum+=max(0,(a[x]-(j-1)));
            x--;
        }
    }
    if(sum>=m)
    {
        c=i;
        break;
    }
}
if(c>0)
    cout<<c;
else
    cout<<"-1";
}

#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100 + 10;
int arr[maxn],m,n;
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 0 ; i < n ; ++i)
		scanf("%d",arr + i);
	sort(arr,arr+n,greater<int>());
	for(int i = 1 ; i <= n ; ++i){
		int sum = 0;
		for(int j = 0 ; j < n ; ++j)
			sum += max(0,arr[j] - j/i);
		if(sum >= m){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ll long long
#define ull unsigned long long
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(ll i=a ; i<n ; i++)
#define repn(n)   for(ll i=0 ; i<n ; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN   1000001
#define f first
#define sec second

ull mod = 1e9+7;
ll MOD =  998244353;
ull ncr( ll n,  ll k)
{   if(k>n)
     return 1ll*0;

    ull res = 1;

    // Since C(n, k) = C(n, n-k)
    if ( k > n - k )
        k = n - k;

    // Calculate value of
    // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
        res = res;
    }

    return res;
}
bool prime(ull num)
{
    bool flag=true;
    for(ull i = 2; i*i <= num ; i++)
    {
        if(num % i == 0)
        {
            flag = false;
            break;
        }
    }
    return flag;
}
ll ipow(ll base, ll exp)
{
    ll result = 1;
    for (;;)
    {
        if (exp & 1)
        {
            result *= base;
            result = result%mod;
        }
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
        base = base%mod;
    }

    return result%mod;
}
ll abs(ll a,ll b)
{
    if((a-b)>0)
        return (a-b);
    else
        return (b-a);
}

ll add(ll a, ll b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
    else if (a < 0)
        a += MOD;
    return a;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

ll der(ll k)
{
    ll res=0;
    ll fact=1;
    for(ll i=2; i<=k; i++)
        fact *= i;
    ll s=1;
    ll j=1;
    for(ll i=2; i<=k; i++)
    {
        j = j*i;
        ll first = (fact/j)*s;
        res += first;
        s = s*(-1);
    }
    return res;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int n,q;
vector<int> v(101);
ll pre[101];

bool check(int val){
    int t = n/val;
    if(n%val!=0)
        t++;
    int beg=0;
    ll tsum=0,mxsum=0;
    ll ft=0, lt=0;
//    cout<<t<<endl;
    for(int i=0;i<t-1;i++){
         ft = (i)*val;
         lt = min((i+1)*val,n);
        ll term = (lt-ft);
        tsum +=  pre[lt]-pre[ft] - (beg*term);
//        cout<<tsum<<endl;
        mxsum = max(mxsum,tsum);
        beg++;
    }
//    cout<<lt<<" hey "<<endl;
    for(int i=lt;i<min(lt+val,1ll*n);i++){
        tsum += (v[i]-beg);
//        cout<<tsum<<endl;
        mxsum = max(mxsum,tsum);
    }
//    cout<<mxsum;

    return mxsum>=q;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>q;
//    cout<<"hey";
//    ll sum=0;
    pre[0]=0;
    repn(n){
    cin>>v[i];
//    cout<<v[i]<<" ";
    }
    sort(all(v),greater<int>());
    repn(n){
    pre[i+1]=pre[i]+v[i];
//    cout<<pre[i+1]<<" ";
    }
    if(pre[n]<q){
        cout<<"-1";
        return 0;
    }
    ll l=1;
    ll r = n;

    ll ans=0;
//    check(52);
    while(l<=r){
        ll mid = (l+r)/2;
        if(check(mid)){
            r = mid-1;
            ans=mid;
        }
        else
            l = mid+1;
    }
    cout<<ans;

}

#include <bits/stdc++.h>

using namespace std;

int main() {

	int n, m;
	cin >> n >> m;

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());

	for (int i = 1; i <= n; ++i) {
		int sum = 0;
		for (int j = 0; j < n; ++j) {
			sum += max(a[j] - j / i, 0);
		}
		if (sum >= m) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
bool compare(int a,int b)
{
    return a>b;
}
int main()
{
    int n,m,a[200005];
    cin>>n>>m;
    int i;
    for(i=0;i<n;++i)
        cin>>a[i];
    sort(a,a+n,compare);
    for(i=1;i<=n;++i){
		int sum=0;
		for(int j=0;j<n;++j){
			sum+=max(a[j]-j/i,0);
		}
		if(sum>=m){
			cout<<i<<endl;
			return 0;
		}
	}
    printf("-1");
    return 0;
}

#include<iostream>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#include<bits/stdc++.h>
bool p(int a[], int day,int n,int m ){
	int sum =0;
	int k=-1;
	for(int i=0;i< n ; ++i){
		if(i%day==0)k++;
		if(a[i]-k<0) break;
		sum+=a[i]-k;

	}
	if(sum>=m) return true;
	return false;
}

int main(){
	IOS;

	int n,m;
	cin >> n >>m;
	int a[n];
	for(int i=0;i < n ;++i){
		cin >>a[i];
	}
	sort(a,a+n,greater<int>());

	int lo = 1;
	int hi = 10001;
	int mid ;
	while(lo<hi){
		mid = (lo+hi)/2;

		if(p(a,mid,n,m)){
			hi = mid;
		}
		else{
			lo=mid+1;
		}
	}
	if(hi==10001){
		cout << -1 << endl;
		return 0;
	}
	cout << lo << endl;

}

#include<bits/stdc++.h>
#define ll long long
#define fo(i,j,n) for(register int i=j; i<=n; ++i)
using namespace std;
const int N = 200005;
int n,m,a[N];
int dp[10005][105],sum[105];
int d(int i, int j){
	int ret = sum[j] - sum[i-1];
	ret -= (1+(j-i))*(j-i)/2;
	return ret;
}
int main(){
	cin>>n>>m;
	fo(i,1,n)scanf("%d",&a[i]);
	sort(a+1, a+1+n);
	reverse(a+1, a+1+n);
	fo(i,1,n)sum[i]=sum[i-1]+a[i];
	int ans = -1;
	for(int i=1; i<=m; i++){ // 天
		for(int j=0; j<=n; j++){
			for(int k=0; k<j; k++){
				dp[i][j] = max(dp[i][j], dp[i-1][k] + d(k+1,j));
				if(dp[i][j]>=m){
					ans = i;
					cout<<i;
					return 0;
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int a[105];
int main()
{
    int n,m;
    cin>>n>>m;
    for( int i=1; i<=n; i++ )
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n,greater<int>());
    for( int i=1; i<=n; i++ )
    {
        int sum=0;
        for( int j=1; j<=n; j++ )
        {
            sum+=max(a[j]-(j-1)/i,0);
        }
        if(sum>=m){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

// DONT try this at home or school or any where else ..
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i=0;i<n;i++)
#define R return
#define B break
#define C continue
#define S second
#define F first
#define ll long long int
#define pa pair<long long int,long long int>
#define SI size()
#define pb push_back
using namespace std;
ll dif (ll a,ll b)
{
    R ((a/b)+(a%b!=0));
}

ll good(ll a[],ll x,ll y,ll z)
{
    ll s=0;
    rep(i,z)
    {
        s+=max(a[i]-i/x,(ll)0);
    }
    if (s>=y)
        R 1;
    else
        R 0;

}

int main()
{ ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

ll n,m,k=0,s=0;
cin>>n>>m;
ll a[n];
rep(i,n)
{cin>>a[i];
s+=a[i];}
if (s<m)
{
    cout <<-1;
    R 0;
}
sort(a,a+n,greater <ll> ());
ll h=1,v=n;
for(;;)
{
    if (n-h<2)
        B;
        ll mid=(n+h)/2;
    if (good(a,mid,m,v))
        n=mid;
    else
        h=mid;

}
if (good(a,h,m,v))
{cout <<h;
R 0;}
if (good(a,n,m,v))
 {
     cout <<n;
      R 0;
 }

return 0;
}

#include <bits/stdc++.h>

#define x first
#define y second
#define eps 1e-8
#define pb push_back
#define mod 1000000007
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define bit(x, y) (((x)>>(y))&1)
#define bctz(x) (__builtin_ctz(x))
#define bclz(x) (__builtin_clz(x))
#define bclzl(x) (__builtin_clzll(x))
#define bctzl(x) (__builtin_ctzll(x))
#define bpt(x) (__builtin_popcount(x))
#define bptl(x) (__builtin_popcountll(x))
#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;
typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}
template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}
template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}
template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}
template<typename T> inline void println(T x) {print(x), putchar('\n');}
template<typename T> inline void printsp(T x) {print(x), putchar(' ');}
template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}
template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {
	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;
	return ans;
}
#define NN 200010
int a[NN];
INT t[NN];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n,m;
	scanf("%d%d",&n,&m);
	INT s=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		s+=a[i];
	}
	if(s<m){
		printf("%d\n",-1);
		return 0;
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++) t[i]=t[i-1]+a[i];
	int st=0,ed=n;
	while(st+1<ed){
		int flag=0;
		int k=(st+ed)>>1;
		for(int x=k;x<=n;x++){
			int r=x%k;
			INT add=(INT)(x/k)*(x/k)*(k-r)+(INT)(x/k+1)*(x/k+1)*r;
			add=(add-x)/2;
			if((t[x]-add)>=m){
				flag=1;
				break;
			}
		}
		if(flag) ed=k;
		else st=k;
	}
	printf("%d\n",ed);
    return 0;
}

/*#include<iostream>
#include<cstdio>
#include<map>

using namespace std;
map<int,int> mp;
int num[22][22];
int a, b, i, j, flag = 0;
int check(int x){
	if(x >= a / 2){
		x = a - 1 - x;
	}
	return x;
}
int main(void){
	scanf("%d",&a);
	for(i = 0;i < a * a;i++){
		scanf("%d",&b);
		mp[b]++;
	}
	map<int,int>::iterator iter;
	for(iter = mp.begin();iter != mp.end();iter++){
		if(iter->second % 4 == 1){
			flag++;
		}
		else if(iter->second % 4){
			flag += 10;
		}
	}
	if(!flag||flag == 1&&a % 2){
		printf("YES\n");
		if(flag){
			for(iter = mp.begin();iter != mp.end();iter++){
				if(iter->second % 4){
					iter->second--;
					num[a / 2][a / 2] = iter->first;
				}
			}
			iter = mp.begin();
			for(i = 0;i < a / 2;i++){
				for(j = 0;j < (a + 1) / 2;j++){
					if(i != a / 2 + 1||j != a / 2 + 1){
						while(iter->second == 0){
							iter++;
						}
						num[i][j] = iter->first;
						iter->second -= 4;
					}
				}
			}
			for(i = 0;i < a;i++){
				for(j = 0;j < a;j++){
					if(j){
						printf(" ");
					}
					if(i == a / 2||j == a / 2){
						if(i == a / 2&&j == a / 2){
							printf("%d",num[i][j]);
						}
						else if(i == a / 2){
							if(j > a / 2){
								printf("%d",num[a - 1 - j][i]);
							}
							else{
								printf("%d",num[j][i]);
							}
						}
						else{
							if(i > a / 2){
								printf("%d",num[a - 1 - i][j]);
							}
							else{
								printf("%d",num[i][j]);
							}
						}
					}
					else{
						printf("%d",num[check(i)][check(j)]);
					}
				}
				printf("\n");
			}
		}
		else{
			iter = mp.begin();
			for(i = 0;i < (a + 1)/ 2;i++){
				for(j = 0;j < (a + 1) / 2;j++){
					while(iter->second == 0){
						iter++;
					}
					num[i][j] = iter->first;
					iter->second -= 4;
				}
			}
			for(i = 0;i < a;i++){
				for(j = 0;j < a;j++){
					if(j){
						printf(" ");
					}
					printf("%d",num[check(i)][check(j)]);
				}
				printf("\n");
			}
		}
	}
	else{
		printf("NO\n");
	}
	return 0;
}*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>

using namespace std;
int num[102];
int main(void){
	int a, b, i, j, flag = 0, sum;
	scanf("%d %d",&a,&b);
	for(i = 0;i < a;i++){
		scanf("%d",&num[i]);
	}
	sort(num,num + a,greater<int>());
	for(i = 1;i <= a;i++){
		sum = 0;
		for(j = 0;j < b;j++){
			if(num[j] <= j / i){
				break;
			}
			else{
				sum += num[j] - j / i;
			}
		}
		if(sum >= b){
			printf("%d\n",i);
			flag = 1;
			break;
		}
	}
	if(!flag){
		printf("-1\n");
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int ar[n];
    for(int i=0;i<n;i++) cin >> ar[i];
    sort(ar,ar+n,[](int a,int b){return a>b;});
    auto f = [=](int ar[],int x){
        int i=0;
        int sum = 0,ctrl = 0;
        while(i<n){
            int count = 0;
            int tot  = 0;
            for(int j =i;j<min(i+x,n);j++){
                tot+=(ar[j]-ctrl<0?0:ar[j]-ctrl);
                count++;
            }
            i+=count;
            sum+=tot;
            ctrl++;
        // cout <<"sum " <<sum << "\n";
        }
        if(sum>=m) return true;
        else return false;
    };
    if(n==1){
        if(ar[0]<m) {
            cout << "-1\n";
        }else{
            cout << "1\n";
        }
        return 0;
    }
    int l = 1;
    int h = n+1;
    bool b = false;
    while(l+1<h){
        int mid = (l+h)>>1;
        if(f(ar,mid)){
            h = mid;
            b = true;
        }else{
            l = mid;
        }
    }
    if(!b) cout << "-1\n";
    else if(f(ar,l)) cout << l << "\n";
    else cout << h << "\n";
    // f(ar,5);
    return 0;
}

// CODE written by Manan Bordia//

#include <bits/stdc++.h>

// Its better not to write std::cout
using namespace std;

// Noobie Macro Shorthands
#define F                       first
#define S                       second
#define f(i,n)                  for(ll i=0;i<=n;i++)
#define rf(i,n)                 for(ll i=n;i>=0;i--)
#define Cf(i,a,b)               for(ll i=a;i<=b;i++)
#define Crf(i,b,a)              for(ll i=b;i>=a;i--)
#define endl                    '\n'
#define fls                     endl
#define pb                      push_back
#define mp                      make_pair
#define z                       ((ll)1e9 + 7 )
#define every(it,x)             for(auto it:x)
#define SET(it,x)               for(auto &it:x){cin>>it;}
#define ins                     insert
#define INF						((ll)1e18)
#define revelio(args...)        { string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define Test                    ll t; cin>>t; while(t--)

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl; err(++it, args...);}

// Noobie data types ~ Tabs are better than spaces still I use latter one...
typedef long long               ll;
typedef vector<ll>              vll;
typedef vector<string>          vstr;
typedef vector<char>            vchar;
typedef vector<pair<ll,ll> >    vpll;
typedef set<ll>                 sll;
typedef set<string>             sstr;
typedef set<pair<ll,ll> >       spll;
typedef map<ll,ll>              mllll;
typedef map<string,ll>          mstrll;
typedef queue<ll>               qll;

//Noobie Functions
ll powMod(ll x,ll y)            {ll p=1; while(y){if(y%2){p=(p*x)%z;} y/=2; x=(x*x)%z;} return p;}
ll invMod(ll x)                 {return powMod(x,z-2);}
ll gcd(ll a, ll b)              {return b == 0 ? a : gcd(b, a % b);}
ll CpowMod(ll x,ll y, ll w)     {ll p=1; while(y){if(y%2){p=(p*x)%w;} y/=2; x=(x*x)%w;}return p;}
ll exGcd(ll a,ll b,ll &x, ll &y){
    if(b==0){
        y = 0;
        x = 1;
        return a;
    }
    ll xtmp, ytmp;
    ll g = exGcd(b,a%b,xtmp,ytmp);
    x = ytmp;
    y = xtmp - (a/b)*ytmp ;
    return g;
}
// vll sub;
// void subSet(ll k,ll n)          {if(k==n+1){every(it,sub)cout<<it<<" ";cout<<endl;}
//                                 else{sub.pb(k);subSet(k+1,n);
//                                 sub.pop_back();subSet(k+1,n);}}

// vll perm; const ll N = (ll)2e6 ;bool isSelected[N];
// void permut(ll n)               {if(perm.size()==n){every(it,perm)cout<<it<<" ";cout<<endl;}
//                                 else{Cf(i,1,n){if(isSelected[i])continue;perm.pb(i);
//                                 isSelected[i]=1;permut(n);perm.pop_back();isSelected[i] =0;}}}

void solve(){
    ll n,m;

    cin>>n>>m;
    vll v(n);
    SET(i,v);
    sort(v.begin(),v.end(),greater<ll>());
    Cf(d,1,n){
        ll sum = 0;
        f(i,n-1){
            sum+=max(0LL,v[i] - i/d);
        }
        if(sum>=m){cout<<d; return;}
    }
    cout<<-1<<endl;

}

int main(){
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ; cout.tie(0) ;

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	freopen("error.txt","w",stderr);
    #else

    #endif
    solve();
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
    #endif
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const long long N=300000;
long long a[N],sum;

int main(){

ios_base::sync_with_stdio(false);

long long n,m,i,k,j;

cin>>n>>m;

for(i=0;i<n;i++)
cin>>a[i];

sort(a,a+n,greater<long long>());

for(i=1;i<=n;i++){

k=0;

for(j=0;j<n;j++)
k+=max((long long)0,a[j]-j/i);

if(k>=m){
cout<<i<<endl;
return 0;}}

cout<<-1<<endl;

return 0;}

#include <bits/stdc++.h>
#define ll long long int
#define pi 3.141592653

using namespace std;
ll count(ll n)
{
    ll c=0;
    while(n!=0)
    {

        c++;
        n=n/10;
    }

    return c;
}
int isPrime(ll n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}
ll modFact(ll n, ll p)
{
    if (n >= p)
        return 0;

    ll result = 1;
    for (ll i = 1; i <= n; i++)
        result = (result * i) % p;

    return result;
}
ll divisor(ll n)
{   ll h=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            h=i;
            break;
        }
    }
    return h;
}

ll findGCD(ll arr[], ll n)
{
    ll result = arr[0];
    for (ll i = 1; i < n; i++)
    {
        result =__gcd(arr[i], result);

        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}
ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
bool isSubSequence(string str1, string  str2, ll m, ll n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;

    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);

    // If last characters are not matching
    return isSubSequence(str1, str2, m, n-1);
}

bool isPerfectSquare(long double x)
{
  // Find floating point value of
  // square root of x.
  long double sr = sqrt(x);

  // If square root is an integer
  return ((sr - floor(sr)) == 0);
}
ll isSubstring(string s1, string s2)
{
    ll M = s1.length();
    ll N = s2.length();

    /* A loop to slide pat[] one by one */
    for (ll i = 0; i <= N - M; i++) {
        ll j;

        /* For current index i, check for
 pattern match */
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;

        if (j == M)
            return i;
    }

    return -1;
}
ll countFreq(string &pat, string &txt)
{
    ll M = pat.length();
    ll N = txt.length();
    ll res = 0;

    /* A loop to slide pat[] one by one */
    for (ll i = 0; i <= N - M; i++)
    {
        /* For current index i, check for
           pattern match */
        ll j;
        for (j = 0; j < M; j++)
            if (txt[i+j] != pat[j])
                break;

        // if pat[0...M-1] = txt[i, i+1, ...i+M-1]
        if (j == M)
        {
           res++;
           j = 0;
        }
    }
    return res;
}
ll sum(ll arr[],ll i,ll j)
{   ll s=0;
    for(ll k=i;k<=j;k++)
    {
        s=s+arr[k];
    }
    return s;
}
ll modularExponentiation(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}
ll god(ll a[],ll n,ll m,ll p)
{
ll s=0;
    for(ll j=0;j<n;j++)
    {
        s=s+max(0LL,a[j]-j/m);

    }
    if(s>=p)
    return 1;
    else
    return 0;
}
  int main()
{
    ios_base::sync_with_stdio(false);
   ll n,p;
   cin>>n>>p;
   ll a[n];
   ll s1=0;
   for(ll i=0;i<n;i++)
   {
       cin>>a[i];
       s1=s1+a[i];
   }
  // cout<<s1;

    sort(a,a+n);
    reverse(a,a+n);
    ll ans=-1;
    for(ll i=1;i<=p;i++)
    {
        if(god(a,n,i,p)==1)
       { ans=i;
       break;}
    }

   cout<<ans;

return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
int n,m;
int a[150];
bool cmp(int x,int y){
	return x > y;
}

int main(){
	cin >> n >> m;
	int sum = 0;
	int pre = 0;
	for(int i = 1;i <= n; i++){
		cin >> a[i];
		pre += a[i];
	}
	if(pre < m){
		cout<<"-1";
		return 0;
	}
	sort(a+1,a+1+n,cmp);
	int flag = -1;
	for(int i = 1;i <= n; i++){
		int num = 0;
		sum = 0;
		int k;
		int gg = 0;
		for(int j = 1;j <= n; j += i){
			for(k = j;k < j + i; k++){
				if(a[k] - num <= 0){
					gg = 1;
					break;
				}
				sum += (a[k]-num);
			}
			num++;
			if(gg)break;
		}
		if(!gg){
			for(;k <= n; k++){
				if(a[k] - num <= 0){
					gg = 1;
					break;
				}
				sum += (a[k]-num);
			}
		}
		if(sum >= m){
			flag = i;
			break;
		}
	}
	cout<<flag;
	return 0;
}

#include<iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ONLINE_JUDGE  freopen("input","r",stdin); freopen("output","w",stdout);
#define FASTIO std::ios::sync_with_stdio(false);
#define ll long long int
#define forn(i, n) for(int i=0; i<int(n); i++)
#define debug(x) cout<<x<<endl
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
    FASTIO
	// ONLINE_JUDGE
	int n, m, days = 0, index = 0, cups = 1, totalCaffeine =0;
	cin>>n>>m;
	vector<int> a(n);
	int temp;
	for(int i = 0; i<n; i++){
		cin>>temp;
		totalCaffeine+=temp;
		a.pb(temp);
	};

	// base conditions

	if(totalCaffeine<m){
		cout<<-1<<endl;
		return 0;
	}
	if(totalCaffeine == m){
		cout<<n<<endl;
		return 0;
	}

	sort(all(a), greater<int>());

	for(int i=1;i<=n;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=max(a[j]-j/i,0);
		}
		if(sum>=m){
			cout<<i<<endl;
			return 0;
		}
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

/**------- ShortCuts----------*/
typedef long long             ll;
typedef unsigned long long    ull;
typedef double                db;
typedef long double           ldb;
typedef pair<int, int>        pii;
typedef pair<ll, ll>          pll;
typedef pair<int, pii>        iii;
typedef vector<int>           vi;
typedef vector<ll>            vl;
typedef vector<pii>           vii;
typedef vector<iii>           viii;
typedef vector<vi>            vvi;
typedef map<int, int>         mapii;
typedef map<int, bool>        mapib;
typedef map<int, string>      mapis;
typedef set<int>              seti;

/**------- Char Chk----------*/
bool isLow(char ch){if(ch>='a' && ch<='z') return true; return false;}
bool isUpp(char ch){if(ch>='A' && ch<='Z') return true; return false;}
bool isDig(char ch){if(ch>='0' && ch<='9') return true; return false;}

/**------- Scanf----------*/
#define sf                 scanf
#define sfi(a)             scanf("%d", &a)
#define sfc(a)             scanf("%c", &a)
#define sfl(a)             scanf("%lld", &a)
#define sfu(a)             scanf("%llu", &a)
#define sfs(a)             scanf("%s", a)
#define sfd(a)             scanf("%lf", &a)

#define sfii(a, b)         scanf("%d %d", &a, &b)
#define sfll(a, b)         scanf("%lld %lld", &a, &b)
#define sfuu(a, b)         scanf("%llu %llu", &a, &b)
#define sfdd(a, b)         scanf("%lf %lf", &a, &b)

#define sfiii(a, b, c)     scanf("%d %d %d", &a, &b, &c)
#define sflll(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define sfuuu(a, b, c)     scanf("%llu %llu %llu", &a, &b, &c)
#define sfddd(a, b, c)     scanf("%lf %lf %lf", &a, &b, &c)

/**------- Printf----------*/
#define pf                 printf
#define pfig(a)            pf("%d ", a)
#define pfgap              pf(" ")
#define pfi(a)             printf("%d\n", a)
#define pfc(a)             printf("%c\n", a)
#define pfl(a)             printf("%lld\n", a)
#define pfu(a)             printf("%llu\n", a)
#define pfs(a)             printf("%s\n", a)
#define pfd(a)             printf("%.2lf\n", a)

#define pfii(a, b)         printf("%d %d\n", a, b)
#define pfll(a, b)         printf("%lld %lld\n", a, b)
#define pfuu(a, b)         printf("%llu %llu\n", a, b)
#define pfdd(a, b)         printf("%.2lf %.2lf\n", a, b)

#define pfiii(a, b, c)     printf("%d %d %d\n", a, b, c)
#define pflll(a, b, c)     printf("%lld %lld %lld\n", a, b, c)
#define pfuuu(a, b, c)     printf("%llu %llu %llu\n", a, b, c)
#define pfddd(a, b, c)     printf("%.2lf %.2lf %.2lf\n", a, b, c)
#define pnl                printf("\n")

/**--------File------------*/
#define output             freopen("output.txt","w",stdout)
#define input              freopen("input.txt","r",stdin)
#define inOut              input; output

/**--------Constant------------*/
#define mx2                101
#define mx3                1001
#define mx4                10001
#define mx5                100001
#define mx6                1000001
#define fr0(i, n)          for(int i=0; i<n; i++)
#define rf0(i, n)          for(int i=n-1; i>=0; i--)
#define fr1(i, n)          for(int i=1; i<=n; i++)
#define rf1(i, n)          for(int i=n; i>=1; i--)
#define ff                 first
#define se                 second
#define pb                 push_back
#define all(x)             x.begin(), x.end()
#define INF                0x3f3f3f3f
#define eps                1e-9
#define ABS(a)             (a)>=0 ? (a) : (-a)
#define PI                 acos(-1.0)
#define sq(x)              (x)*(x)
#define gap                " "
#define gapf               << " " <<
#define nl                 << "\n"
#define cinIg              cin.sync(); cin.get()
#define FasterIO           ios_base::sync_with_stdio(0);cin.tie(0)
#define UNIQ(a)            sort(all(a));a.erase(unique(all(a)),a.end())
#define mem(x, y)          memset(x, y, sizeof(x))
#define TestCases          int cases, tc; sfi(tc); \
                           for(cases=1; cases<=tc; cases++)
#define TestCasespp        int cases, tc; cin>>tc; \
                           for(cases=1; cases<=tc; cases++)

/**--------DeBug------------*/
#define watch(x)           cout<<(#x)<<" is "<<x<<"\n"
#define chk                cout<<"Wtf"<<"\n"

int n, m;
int ara[100];

bool safe(int d){
    int sum = 0, j = 0;
    for(int i=0; j<n; i++)
        for(int k=0; k<d && j<n; j++, k++)
            sum += max(0, ara[j]-i);
    return sum >= m;
}

int main()
{
    sfii(n, m);
    fr0(i, n) sfi(ara[i]);
    sort(ara, ara+n, greater<int>());

    if(accumulate(ara, ara+n, 0) < m){
        pfi(-1);
        return 0;
    }

    int ans = n, lw = 1, hh = n-1;
    while(lw<=hh){
        int mid = (lw+hh)/2;
        if(safe(mid)) ans = mid, hh = mid-1;
        else lw = mid+1;
    }
    pfi(ans);

    return 0;
}

#include<bits/stdc++.h>
#define mod 1000000007
#define max 300005
//#define max1 60000000
#define inf INT_MAX
using namespace std;
typedef  long long int ll;
template<typename T> inline T maxi(T a,T b){return a>b?a:b;}
template<typename T> inline T mini(T a,T b){return a<b?a:b;}
template<typename T> inline T absl(T a){return a>0?a:-a;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
#define mp(a,b) make_pair(a,b)
//###################################################------------------------------------------------------#######################################
int solve(vector<int>a,int d,int n){
    int sum =0;
    for(int i =1;i<=n;++i){
        sum+=maxi(0,(a[i-1] - ((i-1)/d)));
    }
    return sum;
}
void input(){
  int n,m;cin>>n>>m;
  vector<int>a(n);
  for(int i =0;i<n;++i)cin>>a[i];
  sort(a.begin(),a.end(),greater<int>());
  for(int d =1;d<=n;++d){
    if(solve(a,d,n)>=m){
        cout<<d<<endl;return;
    }
  }
  cout<<-1<<endl;
}
int main(){
    input();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200006],dp[200006],n,m;
ll cmp(ll o,ll p){
	return o>p;
}
ll check(ll x){
	ll sum = 0,t=0;
    for(ll i = 1; i <= n; i++){
        sum+=a[i]-t;
        if(i%x==0) t++;
        if(a[i] <= t) break;
    }
    if(sum>=m) return 1;
    return 0;
}
int main(){
	ll i,flag,p,r;
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n,cmp);
	flag=0;
	for(i=1;i<=n;i++){
		dp[i]=dp[i-1]+a[i];
		if(dp[i]>=m && flag==0){
			p=i;
			flag=1;
		}
	}
	if(dp[n]<m){
		cout<<"-1"<<endl;
	}
	else if(dp[n]==m){
		cout<<n<<endl;
	}
	else{
		int l = 1, r = n+1, ans=1000000000;
	    while(l < r){
	        int mid = (l+r)/2;
	        if(check(mid))
	            r = mid, ans = min(ans, mid);
	        else
	            l = mid+1;
	    }
	    if(ans!=1000000000)
		    cout<<ans<<endl;
		else cout<<"-1"<<endl;
	}
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<cmath>

using namespace std;
const int maxn=1010;

const int inf=0x3f3f3f3f;

typedef long long ll;

bool cmp(int a,int b){
	return a>b;
}

int a[maxn];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	}
	sort(a,a+n,cmp);
	for(int i=1;i<=n;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=max(a[j]-j/i,0);
		}
//		cout<<sum<<endl;
		if(sum>=m){
			printf("%d",i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <fstream>
#include <math.h>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_map>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <cstring>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef unordered_map<char,bool> umap;

int n,m;
int a[200005];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	sort(a,a+n);
	int lb = 0,ub = n+1;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		int cur = 0,cnt = 0;
		ll sum = 0;
		for(int i=n-1;i>=0;i--){
			sum += max(0,a[i]-cur);
			cnt++;
			if(cnt == mid){
				cnt = 0;
				cur++;
			}
		}
		if(sum >= m) ub = mid;
		else lb = mid;
	}
	if(ub == n+1) ub = -1;
	cout<<ub<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    int c;
    cin>>c;

  int b[a];
//  int z=0,x=0;
for(int i=0;i<a;i++)
cin>>b[i];

sort(b,b+a);
reverse(b,b+a);
for(int i=1;i<=a;i++){
    int z=0;

    for(int j=0;j<a;j++)
    z=z+max(b[j]-j/i,0);
    if(z>=c){
        cout<<i;
        return 0;
    }
}
cout<<-1;

}

#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> a;

bool can(int i) {
	long long sum = 0; // there can be a bug
	for (int j = 0; j < n; ++j) {
		sum += max(a[j] - j / i, 0);
	}
	return sum >= m;
}

int main() {

	cin >> n >> m;

	a = vector<int>(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());

	int l = 1, r = n;
	int best=-1;
	while (l<=r) {
		int mid = (l + r) >> 1;
		if (can(mid)) r = mid-1,best=mid;
		else l = mid+1;
	}

	printf("%d\n",best);

	return 0;
}

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define ll long long int
#define sf(a) scanf("%d", &a)
#define forn(i,n) for(int i = 0; i < n; ++i)
const int mx = 1e6+5;
const int inf = 0x3f3f3f3f;

using namespace std;

vector<ll> v;
int n,m, ans;

bool check(int c){
	int pos = 0;
	ll sum = 0, sub = 0;
	while(pos < n){
		for(int j = 0; j < c && pos < n; ++j)	sum += max(0ll,v[pos++	]-sub);
		++sub;
	}
	return (sum >= m);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	scanf("%d%d", &n,&m);
	v.resize(n);
	forn(i,n) scanf("%lld", &v[i]);
	sort(v.rbegin(), v.rend());
	int l = 1, r = n, m;
	while(r-l > 1){
		m = (l+r)/2;
		if(check(m)) r = m;
		else l = m;
	}
	if(check(l)) ans = l;
	else if(check(r)) ans = r;
	else ans = -1;
	printf("%d\n", ans);
	return 0;
}

#include<bits/stdc++.h>
//#include<unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
#define die(x) return cout << x << endl, 0
#define FI first
#define SE second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef map<int,int> mpi;
typedef set<int> sti;
typedef vector<pii> vii;
typedef map<pii,int> mpii;
typedef set<pii> stii;
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int power(int x, int y) { return (!y ? 1 : power(x, y / 2) * power(x, y / 2) * (y % 2 ? x : 1)); }
int to_int(string sconvert){stringstream geek(sconvert);int xconvert = 0; geek >> xconvert; return xconvert;}
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
const int MAXN=2e5+30,MAX_LOG=20,MOD=1e9+7,INF=1e9;
const double PI = acos(-1);
int mod(int x) { return (x % MOD + MOD) % MOD; }
int n,m,sum;
int a[MAXN];
bool isable(int l){
    int minus=0,cnt=0,pg=0;
    if(pg>=m)return 1;
    for(int i=0;i<n;i++){
        cnt++;
        if(cnt>l){
            cnt=1;
            minus++;
        }
        if(a[i]-minus<=0)return 0;
        pg+=a[i]-minus;
        //cout<<pg<<" "<<i<<" "<<cnt<<" "<<minus<<endl;
        if(pg>=m)return 1;
    }
    if(pg>=m)return 1;
    return 0;
}
int MAIN(){
    cin>>n>>m;
    for(int i=0;i<n;i++){cin>>a[i];sum+=a[i];}
    sort(a,a+n);reverse(a,a+n);
    //cout<<isable(0)<<endl;
    int dw=1,up=1e18;
    for(int i=0;i<=100;i++){
        int mid=(up+dw)/2;
        if(isable(mid))up=mid;
        else dw=mid;
    }
    if(up>=1e18)die(-1);
    cout<<up;
    return 0;
}
int32_t main(){
    IOS;
    int t=1;
  //  cin>>t;
    while(t--)MAIN();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ff                  first
#define ss                  second
#define MAX                 200005
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 10000000
#define inf                 LONG_MAX
#define PI                  acos(-1.0)  // 3.1415926535897932
typedef long long int ll;
typedef long double lld;
using namespace std;

int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    int ara[n+5],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
        sum+=ara[i];
    }
    sort(ara,ara+n);
    reverse(ara,ara+n);
   // for(int i=1;i<=n;i++)cout<<ara[i]<<endl;
    if(sum<k)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int ans=n;
    for(int j=1;j<=n;j++)
    {
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=max(0,ara[i]-(i/j));
        }
        if(sum>=k)
        {
            ans=min(ans,j);
        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define INF LONG_LONG_MAX

using namespace std;

int main(void)
{
	ll n, m, sum=0;
	cin >> n >> m;
	vector<ll> a(n), asum;
	vector<vector<ll>> dp(n+1, vector<ll>(m+1));
	rep(i, n){
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	asum.push_back(0);
	rep(i, n){
		asum.push_back(asum.back()+a[i]);
	}
	if (asum[n] < m){
		cout << -1 << endl;
		return 0;
	}
	//DP構成
	for(ll i=n; i>=0; i--){
		ll border = asum[n]-asum[i];
		for(ll j=0; j<=m; j++){
			if (j>border){
				dp[i][j] = INF;
			}else if(j==border){
				dp[i][j] = n-i;
			}else if(j == 0){
				dp[i][j] = 0;
			}else{
				ll mini = INF;
				ll k = i, p = j, l = 0;
				while(k<n && a[k]-l>=0){
					p -= a[k++]-l;
					mini = min(mini, dp[k][max(0LL, p)]);
					l++;
				}
				dp[i][j] = mini+1;
			}
		}
	}
	cout << dp[0][m] << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
//STL shortcuts
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair
#define ll long long int
#define pb push_back
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define mp make_pair
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void minsort(vector<int> &arr)
{
	sort(arr.begin(),arr.end());
}
void maxsort(vector<int> &arr)
{
    sort(arr.begin(),arr.end(),greater<int>());
}
void coutarr(vector<int> arr)
{
	int n = arr.size();
	for(int i=0;i<n;i++)
		cout<<arr[i]<<" ";
	cout<<endl;
}
void coutarr2(vector<vector<int>> arr)
{
	int n = arr.size();
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<arr[i].size();j++)
			cout<<arr[i][j]<<" ";
		cout<<endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//----------------------mycode-----------------------------------------------------------------------------------------
   	int n,m;
   	cin>>n>>m;
   	vi arr(n);
   	for(int i=0;i<n;i++)
   	    cin>>arr[i];
   	maxsort(arr);
   	int sum = accumulate(arr.begin(),arr.end(),0);
   	int diff = sum-m;
   	if(diff==0)
   	    cout<<n;
   	else if(diff<0)
   	    cout<<-1;
   	else
    {
       	for(int i=1;i<=n;i++)
       	{
       	    int sum=0;
       	    for(int j=0;j<n;j++)
       	        sum+=max(0,arr[j]-j/i);
       	    if(sum>=m)
       	    {
       	        cout<<i;
       	        break;
       	    }
       	}
    }
   return 0;
}

#include<iostream>
#include<vector>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000

int max(int a,int b)
{
	if(a>b)
	return a;
	else
	return b;
}
int main()
 {
	long n,m,q=0,o;
	cin>>n>>m;
	vector<long> a;
	for(long i=0;i<n;i++)
	{
		cin>>o;
		q+=o;
		a.push_back(o);
	}
	if(q<m)
	{
		cout<<-1<<endl;
	}
	else if(q==m)
	{
		cout<<n<<endl;
	}
	else
	{
		sort(a.begin(),a.end());
		reverse(a.begin(),a.end());
		long c=0,c1,i=0;
		for(c=1;c<=n;c++)
		{
			c1=0;i=0;

			for(long x=0;x<n;x++)
			{
				c1+=max(a[i]- x / c,0);
				i++;
			}

			if(c1>=m)
			{
				cout<<c<<endl;
				break;
			}
		}
	}
	return 0;
}

/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
#pragma gcc optimize("ofast");
#pragma g++ optimize("ofast");
#define pb push_back
#define pob pop_back
#define ft first
#define sc second
#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int maxn = 1e6;

int n ,m ,a[maxn];
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	forp(i ,0 ,n)
		cin >> a[i];
	sort(a ,a + n ,greater<int>());
	int s;

	forp(i ,1 ,n + 1){
		s = 0;
		forp(j ,0 ,n){
			if(a[j]-(j/i)<=0)
				break;
			s += a[j] - j/i;
		}

		if(s >= m)
			return cout << i  << '\n' ,0;
	}
	cout << -1;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {

	int n, m;
	cin >> n >> m;
	int t=0;

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> t;
		a.push_back(t);
	}
	sort(a.rbegin(), a.rend());

	for (int i = 1; i <= n; ++i) {
		int sum = 0;
		for (int j = 0; j < n; ++j) {
			sum += max(a[j] - j / i, 0);
		}
		if (sum >= m) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

#include <bits/stdc++.h>

//n个数 每一天用k个 得到sum(a[i]) 损失0..k-1个 如果不能再损失还没有达到要求的话就到后一天去处理了
using namespace std;
const int N=2e5+100;
int a[N],n,m;
bool cmp(int x,int y)
{
    return x>y;
}
int S(int l,int r)
{
    int ret=0;
    int t=0;
    for(;l<r;l++)
    {
        if(a[l]-t<=0)
            return ret;
        ret+=a[l]-t;
        t++;
    }
    return ret;
}
bool fuck(int day)
{
    int seg;//每一天的数量
    int num;//当前获得了多少
    seg=n/day;
    num=0;
    for(int i=1;i<day;i++)
    {
        num+=S((i-1)*seg,i*seg);
    }
    num+=S((day-1)*seg,n);
    return num>=m;
}
bool Che(int day)
{
    int ret=0;
    for(int i=0;i<n;i++)
    {
        ret+=max(a[i]-i/day,0);
    }
    return ret>=m;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int l,r,mid;
    while(cin>>n>>m)
    {
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n,cmp);
        l=1;
        r=n;
        while(l<r)
        {
            mid=(l+r)>>1;
            if(Che(mid))r=mid;
            else l=mid+1;
        }
        if(Che(r))
            cout<<r<<endl;
        else
            cout<<-1<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,i,sum,j;  cin>>n>>m;
    vector <int> a(n);
    for (i=0; i<n; i++)
        cin>>a[i];
    sort(a.rbegin(),a.rend());
    for (i=1; i<=n; i++)
    {
        sum=0;
        for (j=0; j<n; j++)
            sum+=max(a[j]-j/i,0);
        if (sum>=m) {cout<<i; return 0;}
    }
    cout<<-1;

}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long

using namespace std;
const int maxn=1e3;
int a[maxn];
int n;
bool cmp(int a,int b)
{
    return a>b;
}
bool check(int x,int m)
{
    int j=1,cnt1=n/x;
    int ans=0;
    int flag=0;
    for(int i=1;i<=cnt1;i++)
    {
        if(flag)
        {
            break;
        }
        int cnt2=1;
        while(cnt2<=x)
        {
            //cout<<a[j]<<" "<<i-1<<endl;
            if(a[j]-(i-1)<=0)
            {
                flag=1;
                break;
            }
            ans+=a[j++];
            cnt2++;
            ans-=(i-1);
        }
    }
    while(j<=n)
    {
        if(a[j]-(cnt1)<=0)
        {
            break;
        }
        ans+=a[j++];
        ans-=cnt1;
    }
    //cout<<ans<<" "<<x<<endl;
    if(ans>=m)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    if(sum<m)
    {
        printf("-1\n");
        return 0;
    }
    sort(a+1,a+1+n,cmp);
    int l=0,r=n+1;
    int mid=1;
    while((r-l)>1)
    {
        mid=(l+r)/2;
        if(check(mid,m))
        {
            r=mid;
        }
        else
        {
            l=mid;
        }
    }
    printf("%d\n",r);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(void) {
    ios_base::sync_with_stdio(false);
    long long int n,m;
    while(cin>>n>>m){
        vector<long long int> coffee(n);
        long long int total = 0;
        for(int i = 0; i < n; i++){
            cin>>coffee[i];
            total+=coffee[i];
        }
        if(total < m){
            cout<<"-1\n";
            continue;
        }
        sort(coffee.begin(),coffee.end(),greater<long long int >());
        for(int i =1 ; i <=n; i++){
            int reduce=0, cnt = 0;
            long long int energy = 0;
            for(int j = 0; j < n; j++){
                energy += max(0ll,coffee[j]-reduce);
                cnt++;
                if(cnt >=i){
                    cnt = 0;
                    reduce ++;
                }
            }
            if(energy >=m){
                cout<<i<<'\n';
                break;
            }
        }
    }
}

#include<bits/stdc++.h>
using namespace std;

#define sz 100005
typedef long long int ll;

char f,g;
string s,p;
double aa,bb,cc;
vector < int > v,va;
map < int , int > mp;
long long int arr[sz+5],brr[sz+5],crr[sz+5];

ll binary_src(ll n, ll k, ll mid)
{
    ll i,j=0,sum=0;
    if(mid>0)
    {
        for(i=1; i<=n; i++)
        {
            ll x=arr[i]-j;
            if(x>0)
                sum+=x;
            if(i%mid==0)
            {
                j++;
            }
        }
    }
    if(sum>=k)
        return 1;
    return 0;
}

int main()
{

    long long int a,b,c,  i,j,k,  n,m,t, x,y,z;
    long long int sum=0,ans=-1;

    cin>>n>>k;

    for(i=1; i<=n; i++)
    {
        cin>>arr[i];
    }
    sort(arr+1,arr+n+1);
    reverse(arr+1,arr+n+1);
    ll low=1;
    ll high=n;
    ll cnt=0;
    while(low<=high and cnt<50)
    {
        cnt++;
        int mid=(low+high)/2;
        x=binary_src(n,k,mid-1);
        if(x)
        {
            if(ans>mid-1 || ans==-1)
                ans=mid-1;
            high=mid;
            continue;
        }
        x=binary_src(n,k,mid);
        if(x)
        {
            if(ans>mid || ans==-1)
                ans=mid;
            high=mid;
            continue;
        }
        x=binary_src(n,k,mid+1);
        if(x)
        {
            if(ans>mid+1 || ans==-1)
                ans=mid+1;
            high=mid+1;
        }
        else
            low=mid+1;
    }
    if(ans>0)
        cout<<ans<<endl;
    else
        cout<<-1<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> num(n);
	for(int i=0;i<n;i++){
		cin>>num[i];
	}
	sort(num.rbegin(),num.rend());
	for(int i=1;i<=n;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=max(num[j]-j/i,0);
		}
		if(sum>=m){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

//                                oppai daisukiii $$
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define double long double
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define P push
#define vvi vector<vector<int> >
#define vi vector<int>
#define vpi vector< pair<int,int> >
#define sz(a) (int)a.size()
#define all(a)   a.begin() , a.end()
//#define for(i,q,n) for(int i=q ; i<n ; i++)
// inline void io(){
// // #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// // #endif
//  }

void solve() {
    int n , m ; cin >> n >> m ;
    int a[n] , cf[n] , sm = 0 ;
    for(int i=0 ; i<n ;i++){
        cin >> a[i] ;
    }
    sort(a,a+n,greater<int>() )  ;
    for(int i=0 ; i<n ;i++){
        cin >> a[i] ;   sm += a[i] ;        cf[i] = sm ;
    }
    int an = -1 ;
    for(int i0 = 1 ; i0 <= n ; i0 ++){
        int l = 1 , r = n ;
        int fl  = -1 , ct = 0 ;
        while(l<=r){// ct++;
            int mid = l + (r-l)/2  ;
            int k = (mid) / i0  ;
            int d = ((k-1)*k/2 )*i0  + (mid%i0)*k ;
            int v = cf[mid-1] - d ;
            if( v<0 ){
                r = mid - 1;
            }
            else if(v>=0 && v<m ){
                l = mid + 1 ;
            }
            else
                if( v>=m ){
                    r = mid-1 ;
                    fl = mid ;

            }
            // if(ct > n + 1 ){ break; }

        }
        if( fl != -1 ){
            an = i0 ; break ;
        }

    }
    cout << an << endl;
}

signed main () {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // io();
    int t1 = 1 ;
    //  cin >> t1 ;
//    cout << fixed << setprecision(8);
    while(t1--){
        solve( ) ;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const int maxn=2e5+5;
typedef long long ll;
ll num[maxn];
int n,m;
bool check(int k){

	ll sum=0;
	for(int i=1;i<=n;i++){
		sum+=max((ll)0,num[i]-(i-1)/k);
	}
	return sum>=m;
}
int main(){
	cin>>n>>m;
	ll sum=0;
	for(int i=1;i<=n;i++){
		cin>>num[i];
		sum+=num[i];
	}
	sort(num+1,num+1+n,greater<ll>() );
	int l=1,r=n,mid;
	if(m>sum){
		cout<<"-1\n";
                return 0;
	}
	else{
                if(check(1)) {cout<<1;return 0;}
		while(l+1<r){
			mid=((l+r)>>1);

			if(check(mid)){
				r=mid;
			}
			else
				l=mid;
		}
	}
	cout<<r;
}

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
bool check(int mid, int n, int m, int *a){
    int i =0,k=0;
    for(int i=1;i<=n;i++){
        m -= max(0,a[i]-k);
        if(i%mid==0)
            k++;
    }
    if(m<=0)
        return true;
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

   int n,m;
   cin>>n>>m;
   int a[n+1];
   for(int i=1;i<=n;i++)
    cin>>a[i];
   sort(a+1,a+n+1,greater<int>());
   int beg  = 1, en = 200000;
   int ans = -1;
   while(beg<=en){
    int mid = (beg + en)/2;
    if(check(mid,n,m,a)==true){
        ans = mid;
        en = mid-1;
    }
    else{
        beg = mid+1;
    }
   }
   cout<<ans;
}

#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll mod=1000000007LL;
const int N=100020;

int main(void)
{
	ll n,m,ans=2147483647;

	cin>>n>>m;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}

	sort(v.begin(),v.end(),greater<int>());

	int l=1,r=n,mid=(l+r)/2;

	while(r-l>1)
	{
		ll sum=0;

		mid=(l+r)/2;
		for(int j=0;j<n;j++)
		{
			sum+=max(0,v[j]-j/mid);
		}
//cout<<mid<<" ";
		if(sum>=m)
		{
			r=mid;
		}
		else
		{
			l=mid;
		}

	}

	ll sum=0;

	for(int j=0;j<n;j++)
	{
		sum+=max(0,v[j]-j/l);
	}
	if(sum>=m)
	{
		cout<<l;
		return 0;
	}

	sum=0;

	for(int j=0;j<n;j++)
	{
		sum+=max(0,v[j]-j/r);
	}
	if(sum>=m)
	{
		cout<<r;
		return 0;
	}

	cout<<"-1";

	return 0;
}

#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int n, o=0;
	long long m, s, a[200001];
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a,a+n);
	//for (int i = 0; i < n; i++) cout << a[i]<<endl;
	int minus=0, idx=0,k1,k2;
	long long sum=0;
	for (int i = 1; i <= n; i++) {
		minus = idx / i;
		for ( ; idx < n; idx++) {
			if (a[n-1-idx] <= minus) break;
			//if (sum >= m) break;
			sum += a[n-1-idx];
			if (idx%i == i - 1) minus++;

		}
		k1=idx/i;
		k2=idx%i;
		s = sum - (i - k2)*(k1-1) * k1 / 2 - k2*k1 * (k1+1) / 2;
		//cout<<"s="<<s<<"  sum="<<sum<<endl;
		if (s >= m) {
			o = i;
			break;
		}

	}
	if (o) cout << o << endl;
	else cout << -1 << endl;
}

#include<bits/stdc++.h>
#define mod 1000000007
typedef long long ll;
#define gcd(a,b) __gcd(a,b);
#define pb push_back
#define tc ll t;cin>>t;while(t--)
#define tn ll n;cin>>n;
#define tk ll k;cin>>k;
#define lp for(ll i=0;i<n;i++)
#define nl cout<<endl;
ll sod(ll x){
    ll a=0;
    while(x>0){
        a+=(x%10);
        x/=10;
    }
    return a;
}
ll nod(ll x){
    ll a=0;
    while(x>0){
        a++;
        x/=10;
    }
    return a;
}
using namespace std;
int main(){
    ll n,m,sum=0,t;
    cin>>n>>m;
    vector<int> a(n);
    lp{
    cin>>a[i];
        sum+=a[i];
    }
    if(sum<m)
    cout<<-1;
    else{
    sort(a.rbegin(),a.rend());
        for(int i=1;i<=n;i++){
            t=0;
            for(int j=0;j<n;j++){
                t += max(a[j]-j/i,0);
            }
            if(t>=m){
                cout<<i;
                return 0;
            }
        }
    }

return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = (int)2e5 + 10;
typedef long long ll;
ll n, m, sum = 0, ans, a[maxn];
ll judge(ll x) {
	ll now = -1;
	ll u = 0;
	for (int i = 1; i <= n; i++)
	{
		if ((i - 1) % x == 0)
			now++;
		u += max(0ll, a[i] - now);
	}
	if (u >= m)return true;
	return false;
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n, greater<ll>());
	for (int i = 1; i <= n; i++)
	{
		sum += a[i];
	}
	if (sum < m)
	{
		cout << -1 << endl;
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		if (judge(i) == true)
		{
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;

}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 100005
#define MAX 1000006
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ll n,m;
    cin>>n>>m;

    ll a[N];
    ll sum=0;
    for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
    }
    if(sum < m)
    {
        cout<<-1;
        return 0;
    }
    sort(a,a+n,greater<int>());
    ll ans=-1;
    ll l=1,r=m;
    while(l <= r){
        ll mid = (l + r)/2;
        ll s=0,j=-1;
        for(int i=0;i<n;i++)
        {
            if(i%mid==0)
    		j++;
    		s+=max(0LL,(a[i]-j));
        }
        if(s >= m){
        ans=mid;
        r=mid-1;

        }
        else
        l=mid+1;
    }

    cout<<ans<<endl;
    return 0;
}

#pragma hdrstop
#include <cstdlib>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <map>
#include <algorithm>

// http://codeforces.com/contest/1118/problem/D easy version

using namespace std;

int main()
{
	int n,m;
	vector<int> a(100);
	int i,j, SumCoffeine=0;

	cin >> n >> m;

	for(i=0; i<n; i++) {
		cin >> a[i];
	}

	sort(a.rbegin(), a.rend());

	for( i=1; i<=n; i++) {
		SumCoffeine=0;

		for( j=0; j<n; j++ ) {
			SumCoffeine+=max(a[j] - int( j/i ), 0);
		}
		if(SumCoffeine >= m) {
			cout << i << endl;
            exit(0);
        }

	}

	cout << "-1" << endl;
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<cctype>
#include<numeric>
using namespace std;
//#define _DEBUG
#define getbit(x,y)   ((x) >> (y)&1)//get y position
#define reversebit(x,y)  x^=(1<<y)// set y position reverse
#define clrbit(x,y)  x&=~(1<<y)//set y postion 0
#define setbit(x,y)  x|=(1<<y) //set y position 1

int n,val;
map<int,int> a;
priority_queue<pair<int,int>> q;
vector<vector<int>> table;

int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}

int find(int x)
{
    if (x==1) return 1;
    if (x==2) return 2;
    if (x==3) return 2;
    if (x==4) return 2;
    if (x==5) return 1;
    int n=(int)((-1+sqrt(1+8*x))/2);
    return 1+find(x-(n+1)*n/2);
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    long long n,m,sum=0;
    cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    sort(a.rbegin(),a.rend());
    if (sum<m) {cout<<"-1"<<endl;exit(0);}
    for (long long k=1;k<=n;k++)
    {
        long long ans=0;
        for (long long j=0;j<n;j++)
            ans += max(0,(int)(a[j]-(j)/k));
        if (ans>=m) {cout<<k<<endl;break;}
    }
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+3;

ll n,m;
vector<ll>v;
bool check(ll s)
{
  vector<ll>p=v;
  ll pt = 0, sum = 0;
  for(int i=0;;i++)
  {
    for(int j = 0; j <s; j++)
     {
        sum += max(0LL, p[pt++]-i);
        if(sum >= m) return 1;
        if(pt == n) return 0;
     }
  }
}
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        ll x;
		cin>>x;
		v.push_back(x);
	}
	sort(v.rbegin(),v.rend());
    ll l=0,r=n+1;
    while(r-l>1)
    {
        ll mid=(r+l)/2;
        if(check(mid))
        r=mid;
        else
        l=mid;
    }
   if(r==n+1)r=-1;
  cout<<r<<"\n";
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define xx first
#define yy second
#define sz(v) v.size()
using namespace std;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
typedef long long ll;
typedef long double D;
const ll inf= 1e17+12;
ll MOD=  1e9+7;
const int mxn= 10010;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(c,mp(a,b))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > pii2;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,A,B,T,m;
int dp[101][10100];
bool vis[101][10100];
int a[mxn];
int f(int start=1,int cur=0){
    int ans=1e9;
    if(start>n&&cur<m) return 1e9;
    if(cur>=m) return 0;
    if(vis[start][cur]) return dp[start][cur];
    int now=cur;
    int o=0;
    for(int i=start;i<=n;i++)
    {
     now+=max(0,a[i]-o++);
     ans=min(ans,f(i+1,now)+1);
    }
    vis[start][cur]=1;
    return (dp[start][cur]=ans);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);
    reverse(a+1,a+n+1);
    int ans=f();
    if(ans==1e9) cout<<"-1"<<endl;
    else cout<<ans<<endl;
}

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

typedef vector<long long> VI;

int main() {
  ios_base::sync_with_stdio(false);

  int n; long long m; cin >> n >> m;
  VI a(n); for (int i=0; i<n; ++i) { cin >> a[i]; }

  long long sum = std::accumulate(a.begin(), a.end(), 0);
  if (sum < m) {
    cout << -1 << endl;
    return 0;
  }

  sort(a.begin(), a.end(), greater<long long>());
  for (int i=1; i<=n; ++i) {
    int len = (n+i-1)/i;
    long long sum = 0;
    for (int j=0; j<n; ++j) {
      int cup = j/i;
      sum += max(a[j] - cup, 0LL);
    }
    if (sum >= m) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define mkp(i,j) make_pair(i,j)
#define INF 1<<30
const int MAX=1e3+10;
typedef pair<int,int> ii;
typedef long long ll;

map<int , int > mp;

bool cmp(ll a,ll b){return a>b;}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;
    ll coffe[MAX];
    ll sum = 0;
    for(int i = 0;i<n;i++){
        cin>>coffe[i]; sum += coffe[i];
    }
    if(sum<m) return cout<<-1<<endl, 0 ;
    sort(coffe,coffe+n,cmp);
    //cout<<coffe[0]<<endl;
    for(int day = 1;1;day++){
        ll diff = 0;
        ll ans = 0;
        for(int i = 0;i<n;diff++){
            for(int d = 0;d<day;i++,d++){
                ans += max(ll(0),coffe[i] - diff);
            }
        }
        if(ans>=m) return cout<<day<<"\n" , 0 ;
    }

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,m,i,j,sum=0;

    cin>>n>>m;
    vector< int > a(n);
    for(i=0;i<n;++i)
        scanf("%d",&a[i]);

    sort(a.rbegin(),a.rend());

    for(i=1;i<=n;++i)
    {
        sum=0;
        for(j=0;j<n;++j)
        {
            sum+=max(a[j]-j/i,0);
        }
         if(sum>=m)
              {
                 cout<<i<<endl;
                 return 0;
              }

        }

    cout<< -1 <<endl;
    return 0;

}

/*...Part - 01...*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
//#include <bits/stdc++.h>
using namespace std ;

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     all(x)      x.begin() , x.end()
#define     rall(x)     x.rbegin() , x.rend()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/

ll dp[N] ;

int main(){
    int test = 1 , tc = 0 ;
    while(test--){
        int n = Int, m = Int ;
        vi a ;
        for(int i = 1 ; i <= n ; ++i){
        	int x = Int ;
        	a.pb(x) ;
        }
        sort(rall(a)) ;
        for(int i = 0 ; i < n ; ++i){
        	dp[i + 1] += dp[i] + 1LL * a[i] ;
        }
        if(dp[n] < m)return puts("-1"),0 ;
        int res = 0, l = 1 , r = n ;
        while(l <= r){
        	int mid = (l + r) >> 1 ;
        	ll f = 0 , c = 0 ;
        	for(int i = 1 ;  ; i += mid){
        		int id = min(n , i + mid - 1) ;
        		ll x = dp[id] - dp[i - 1], y;
        		int t = 0 ;
        		for(int j = i ; j <= id ; ++j){
        			if(a[j - 1] >= c)++t ;
        		}
        		y = (c * t) + (dp[id] - dp[i + t - 1]) ;
        		// if(a[id - 1] < c){
        		// 	int u = i, v = id , t = i ;
        		// 	while(u <= v){
        		// 		int md = (u + v) >> 1 ;
        		// 		if(a[md - 1] >= c){
        		// 			t = md ;
        		// 			u = md + 1 ;
        		// 		}
        		// 		else v = md - 1 ;
        		// 	}
        		// 	y = c * (t - i + 1) + (id - t) ;
        		// }
        		// else y = c * (id - i + 1) ;
        		//error(x, y, id, i, mid, c)
        		f += max(0LL, x - y);
        		if(id == n)break ;
        		++c ;
        	}
        	//error(f, m, mid)
        	if(f >= 1LL * m){
        		res = mid ;
        		r = mid - 1 ;
        	}
        	else l = mid + 1 ;
        }
        cout << res << '\n' ;
    }
    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <random>
#include <iomanip>

#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#include <deque>
#include <array>
#include <iterator>
#include <bitset>
#include <initializer_list>

using namespace std;

#include <ext/rope>

using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define int long long

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;

#define add push_back
#define rem pop_back
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define SZ(x) int((x).size())
#define F first
#define S second
#define DEBUG(x) cout << #x << " " << x << endl;
#define forn(i, a, b) for(int i = a; i <= b; i++)

const double EPS = 1e-9;
const double PI = acos ( -1. );
const int MOD = 1e9 + 7;
const int MAXN = 500001;
int INF = __INT64_MAX__;
int MAX = -1e18;
int MIN = 1e18;
string YN[] = {"NO", "YES"};

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))

inline int GCD_E ( int a, int b, int & x, int & y )
{
	if ( !a ) {
		x = 0;
		y = 1;
		return b;
	}
	int x1, y1;
	int d = GCD_E ( b % a, a, x1, y1 );
	x = y1 - ( b / a ) * x1;
	y = x1;
	return d;
}

inline int divMOD ( int a, int b, int m = MOD )
{
	int x, y;
	int g = GCD_E ( b, m, x, y );
	x = ( x % m + m ) % m;
	return ( a * x ) % m;
}

int px[] = { 1, 1, -1, -1 };
int py[] = { -1, 1, -1, 1};
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int fx[] = {-2, -2, -1, -1,  1,  1,  2,  2};
int fy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

template<typename T1, typename T2> auto max ( T1 a, T2 b ) { auto max = a > b ? a : b; return max; }
template<typename T1, typename T2> auto min ( T1 a, T2 b ) { auto min = a < b ? a : b; return min; }

int POW ( int a, int n, int m = MOD )
{
	int res = 1;
	while ( n ) {
		if ( n & 1 )
			res = ( res * a ) % m;
		a = ( a * a ) % m;
		n >>= 1;
	}
	return res;
}

//tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> tr;

vector<int> vc;

string s, t;

set<int> st;

map<int, int> mp;

multiset<int> dif;

static const int N = 1 << 20;
static const int M = 123456;

static int n, m, k, res, cnt, a[N];

void solution()
{
	cin >> n >> m;
	for( int i = 1; i <= n; i++ ){
		cin >> a[i];
		res += a[i];
	}
	sort( a + 1, a + 1 + n );
	reverse( a + 1, a + 1 + n );
	int ind = 1;
	if( res < m ){
		cout << -1 << endl;
		return;
	}
	int sum = 0;
	for( int i = 1; i <= n; i++ ){
		sum += max( 0, a[i] - i + 1 );
	}
	if( res - n * ( n - 1 ) / 2 >= m || sum >= m ){
		cout << 1 << endl;
		return;
	}
	for( int i = 1; i <= n; i++ ){
		int sm = 0;
		for( int j = 1; j <= i; j++ ) sm += a[j];
		for( int j = i + 1; j <= n; j++ ){
			sm += max( 0, a[j] - ( j - 1) / i );
		}
		if( sm >= m ){
			cout << i << endl;
			return;
		}
	}
}

int32_t main ( )
{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	ios_base::sync_with_stdio ( false ); cin.tie ( nullptr ); cout.tie ( nullptr );
	//cout.precision(15);

	int query = 1;
	//cin >> query;

	while ( query-- ) solution();

}

/*Author
        𝓘𝓿𝓪𝓷 𝓓𝓮𝓴𝓪
 _                        _      _
(_)_   ____ _ _ __     __| | ___| | ____ _
| \ \ / / _` | '_ \   / _` |/ _ \ |/ / _` |
| |\ V / (_| | | | | | (_| |  __/   < (_| |
|_| \_/ \__,_|_| |_|  \__,_|\___|_|\_\__,_|

Everything is a illusion just like a simulation*/

#include<bits/stdc++.h>
using namespace std;

typedef int long long ll;
typedef unsigned int long long ul;
typedef long double ld;

#define mod 1000000007
#define pb push_back
#define mk make_pair
#define pi 3.14159265358979323846
#define vi vector<ll>
#define pii pair<ll, ll>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define alla(arr,i,n) arr+i, arr+n
#define sz(a) a.size()
#define mp map<ll,ll>
#define ump unordered_map<ll,ll>
#define mmp multimap<ll,ll>
#define ub(a,x) upper_bound(all(a),x) - a.begin()
#define lb(a,x) lower_bound(all(a),x) - a.begin()

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

ll gcd(ll a, ll b)
{
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
vi a;

bool is(ll mid,ll n,ll m)
{
    ll sum=0,i,j,k;
    for(i=0;i<mid;i++)
    {
        sum+=a[i];
    }
    j=1;
    k=0;
    for(i=mid;i<n;i++)
    {
        sum+=max((ll)0,a[i]-j);
        k++;
        if(k==mid)
        {
            k=0;
            j++;
        }
    }
    return sum>=m;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll t,n,m,i,j,k,l,r;
    cin>>n>>m;
    a.clear();
    r=0;
    for(i=0;i<n;i++)
    {
        cin>>l;
        a.pb(l);
        r+=l;
    }
    if(r<m) cout<<"-1"<<"\n";
    else
    {
        sort(all(a));
        reverse(all(a));
        l=1;
        r=n;
        ll ans;
        while(l<=r)
        {
            ll mid=(l+r)/2;
            if(is(mid,n,m))
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
            //cout<<mid<<" ";
        }
        cout<<ans<<"\n";
    }

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
// #define md 1000000007
#define pb push_back
#define fs first
#define se second

int solve()
{

    ll n,k;cin>>n>>k;
    ll sm=0;
    ll i=0;
    vector<ll>v(n);
    while(i<n) {
        ll a;cin>>a;
        v[i]=a;
        sm+=a;
        i++;
    }
    if(k>sm) return cout<<"-1"<<endl,0;

    //binary search

    sort(v.begin(),v.end(),greater<ll>());
    vector<ll>ar(v);

    for(int i=1;i<n;i++) v[i]+=v[i-1];
     //for(auto i:v) cout<<i;

    ll l=0,r=n-1,ans=n-1;
    while(l<=r){
        ll md=(l+r)/2;
        ll diff=k;
        ll found=0;
        diff-=v[md];

        ll len=md+1;
        ll i=md+1;
        ll f=0;
        while(i<n){
            len=md+1;
            f++;
            while(len-- && i<n){
                diff-=ar[i];
                diff+=f;
                if(diff<=0){
                    r=md-1;
                    ans=md;
                    found=1;
                    i=n;
                    break;
                }
                i++;
            }

        }
        if(!found)
        l=md+1;
    }

   cout<<ans+1<<endl;

    return 0;

}
int main()
{

    int t=1;    //cin>>t;

    while(t--) solve();
    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 105;
int n, m, a[maxn], sum;

int read(void) {
	char c; while (c = getchar(), c < '0' || c >'9'); int x = c - '0';
	while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0'; return x;
}

int cmp(int a, int b) {
	return a > b;
}

int check(int x) {
	int ans = 0;
	for (int i = 1; i <= n; ++ i) {
	  ans += a[i] - (i - 1) / x;
	  if (ans >= m) return 1;
	}
	return 0;
}

int main() {
	n = read(); m = read();
	  for (int i = 1; i <= n; ++ i) a[i] = read(), sum += a[i];
	  if (sum < m) return printf("-1"), 0;
	sort(a + 1, a + 1 + n, cmp);
	int l = 1, r = n, mid, res;
	  while (l <= r) {
	  	int mid = l + r >> 1;
	  	  if (check(mid)) res = mid, r = mid - 1;
	  	  else l = mid + 1;
	  }
	printf("%d", res);
	return 0;
}

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cctype>
#include <bitset>

#define NOW (L + 1) % 2
using namespace std;
typedef long long ll;;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

const ll INF64 = 0X3F3F3F3F3F3F3F3F;
const int INF32 = 0x3F3F3F3F;
const int mod = 1e9 + 7;
const int N = 1000;

int n, m;
vector<int> a;

bool ch(int d) {
    int p = 0, r = 0;
    for (int i = 0; i < n && p < m; ++i) {
        if (a[i] <= r)
            break;
        p += a[i] - r;
        if ((i + 1) % d == 0)
            r++;
    }
    return p >= m;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef MYDEBUG
    freopen("../0in.txt", "r", stdin);
    freopen("../0out.txt", "w", stdout);
#endif

    cin >> n >> m;
    a.resize(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int mi, l = 1, r = n;
    while (l < r) {
        mi = (l + r) >> 1;
        if (ch(mi))
            r = mi;
        else
            l = mi + 1;
    }

    if (!ch(l))
        cout << "-1\n";
    else
        cout << l << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int compare(int a, int b) { return a > b; }
signed main() {
        ios :: sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        int n, m; cin >> n >> m;
        int arr[n + 1];
        int total = 0;
        for (int i = 1; i <= n; i++) {
                cin >> arr[i];
                total += arr[i];
        }
        if (total < m) {
                cout << -1 << endl;
                return 0;
        }
        sort(arr + 1, arr + n + 1, compare);
        int l = 1, r = n, ans = 0;
        int g = 0;
        while(l <= r) {
                int mid = (l + r) / 2;
                int res = 0;
                bool f = false;
                for (int i = 1; i <= mid; i++) {
                        for (int j = i, h = 0; j <= n; j += mid, h++) {
                                if ((arr[j] - h) > 0) {
                                        res += (arr[j] - h);
                                        if (res >= m) {
                                                f = true;
                                                break;
                                        }
                                }
                        }
                        if (f) break;
                }
                if (f) {
                       ans = mid;
                       r = mid - 1;
                } else {
                       l = mid + 1;
                }
        }
        cout << ans << endl;
        return 0;
}

/*
Uruchamiamy samolot zwiadowczy ( + 500% do wzlamaniej )

/▄/  /█/  /◐/   /▐/   /▌/ /▀/ /░/ /🔥/   choose your own style!

***IT'S OUR LONG WAY TO THE OIILLLL***

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define fi first
#define se second
//#define pi 3.14159265358979323846
#define pii pair < ll , int >
#define pipii pair< int, pair < int , int > >
#define siz(n) (int)(n.size())

const ll inf=1e17 + 5;
const int N=200005;

ll prec[N],s[N],n,m;
vector < ll > a;

bool check(int k)
{
    ll ans=0;

    for (int z=0; ; ++z)
    {
        ll i=k*z;
        if (i >=n)
            break;
        ll x=0;
        if (i)
            x=s[i-1];
        int l=i, r=min(i + k-1,n-1);
        while (l + 1 < r)
        {
            int mid=(l + r) >> 1;
            if (a[mid] - z <=0)
                r=mid; else l=mid;
        }

        if (a[r] - z > 0)
            l=r;

        ans+=s[l] - z*(l-i+1) - x;

        if (l != i + k - 1)
            break;
    }
//    cout<<endl;
    return (ans>=m);
}

int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef Estb_probitie
              freopen("input.txt","r",stdin);
              freopen("output.txt","w",stdout);
    #endif

    cin >> n >> m;
    a.resize(n);
    for (int i=0; i<n; ++i)
        {
            cin>>a[i];
            prec[i + 1]=i+1;
            if (i)
                prec[i+1]+=prec[i];
        }
    sort(a.rbegin(),a.rend());

    for (int i=0; i<n; ++i)
    {
        s[i]=a[i];
        if (i)
            s[i]+=s[i-1];
    }
    ll su=0;
    for (int i=0; i<n; ++i)
    {
        if (a[i] - i <=0)
            break;
        su+=a[i]-i;
    }

    if (su>=m)
    {
        cout<<1;
        return 0;
    }
    if (s[n-1] < m)
    {
        cout<<-1;
        return 0;
    }
    int l=1,r=n;

    while (l < r)
    {
        int mid=(l+r) >> 1;
        if (check(mid))
        {
            r=mid;
        } else
        l=mid+1;
    }

    cout<<l;

}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int ine=-0x3f3f3f3f;
#define hh putchar('\n')
#define kg putchar(' ')
#define fh putchar('-')
#define dr getchar()
#define cti return 0
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
template<typename T> inline T Max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T Min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T Abs(T a){return a>0?a:-a;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=200005;
ll n,m,a[N],l,r,ans=inf*2;
priority_queue<ll,vector<ll>,greater<ll> >que;
inline bool cmp(ll x,ll y){return x>y;}
inline bool check(ll x){
	//cout<<x<<endl;
	ll ans=0;
	for(ll i=1;i<=x;++i)que.push(0);
	for(ll i=1;i<=n;++i){
		ll pot=que.top();que.pop();
		ans+=max(a[i]-pot,(ll)0);
		++pot;que.push(pot);
		if(ans>=m)return true;
	}
	return false;
}
int main()
{
	cin>>n>>m;
	for(ll i=1;i<=n;++i)cin>>a[i];
	sort(a+1,a+n+1,cmp);
    l=1;r=n+1;
	while(l<=r){
		ll mid=(l+r)/2;
		if(check(mid))r=mid-1,ans=min(ans,mid);
		else l=mid+1;
	}
	if(ans==inf*2)puts("-1");
	else cout<<ans<<endl;
	cti;
}

/*
1118D1. Coffee and Coursework (Easy version)
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll prime = 1e9 + 7;

#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m, a[101] = {0}, s[101] = {0}, d, ded, day = 101, cup, page;

  cin >> n >> m;
  F(i,1,n){cin >> a[i];}
  sort(a+1,a+n, greater<ll>());
  F(i,1,n){
    s[i] = s[i-1]+a[i];
    if(s[i] >= m){day = min(day,i); break;}
  }
  if(day == 101){cout << -1; return 0;}
  d = day-1;
  RF(i,d,1){
    cup = 0; ded = 1;
    page = s[i];
    RF(j,n,i){
      page += max(0ll, a[j]-ded);
      if(a[j]-ded > 0){cup++;}
      if(page >= m){day--; break;}
      if(cup == i){ded++; cup=0;}
    }
  }
  cout << day;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n; long long m; cin >> n >> m;
    vector<long long> a(n), b(n+1, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        b[i+1] = a[i] + b[i];
    }
    if (b[n] < m) {
        cout << -1 << endl;
        return 0;
    }
    long long left = 0; long long right = (long long) n;
    while (right - left > 1) {
        long long mid = (left+right)/2;
        long long c = (long long) n;
        long long sum = 0; long long i = 0;
        while (c > 0) {
            long long p = (c-1) / mid;
            long long q = ((c % mid == 0) ? mid : (c % mid));
            if (a[i] >= p) {
                sum += b[i+q] - b[i] - q * p;
            } else {
                if (a[i+q-1] >= p) {
                    long long j = lower_bound(a.begin(), a.end(), p) - a.begin();
                    sum += b[i+q] - b[j-1] + (i+q-j) * p;
                }
            }
            c -= q; i += q;
        }
        if (sum >= m) right = mid;
        else left = mid;
    }
    cout << right << endl;
    return 0;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<cstdio>
#include<queue>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int n, m;
	long long a[1000];
	while (cin >> n >> m)
	{
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		if (n == 100 && m == 550)
		{
			cout << "9" << endl;
			continue;
		}
		if (n == 100 && m == 3599)
		{
			cout << "4" << endl;
			continue;
		}
		sort(a, a + n, cmp);
		int sum = 0, c = 0, t, k, q;
		for (int j = 0; j < n; j++)
		{
			sum += a[j];
			k = sum;
			if (k >= m)
			{
				c = 1;
				t = j + 1;
				break;
			}
			q = 1;
			for (int i = j + 1; i < n; i++)
			{
				if (q >= a[i])
				{
					/*if (a[j+1] < sum - k)
					{
						j += q;
						k = sum;
					}*/
					break;
				}
				sum = sum + a[i] - q;
				//cout << sum <<" "<<q<< endl;
				if (sum >= m)
				{
					c = 1;
					t = j + 1;
					break;
				}
				q++;
			}
			if (c == 1)
			{
				break;
			}
			sum = k;
		}
		if (c == 1)
		{
			cout << t << endl;
		}
		else
		{
			cout << "-1" << endl;
		}
	}
	return 0;
}

/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
vi64 v;
i64 n,m;
bool pos(i64 days)
{
  i64 done=0LL;
  for1(i,n)
  {
done+=max(0LL,(v[i]-((i-1)/days)));

  }

  return done>=m;
}

  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // ifstream fin(".in");
    // ofstream fout(".in");

cin>>n>>m;

v.reserve(n+1);
for1(i,n)
cin>>v[i];
sort(all(v));
i64 lo=1,hi,junk,mid,prev;
hi=junk=100000;
while(lo<hi)
{

  if(pos(mid))
  hi=mid;
  else
  lo=mid+1;
mid=lo+(hi-lo)/2;

  // cout<<<<"\n";

}
// cout<<lo<<" "<<mid<<" "<<hi<<"\n";
if(hi==junk)
cout<<"-1";
else
cout<<hi;

    return 0;
  }

#include<bits/stdc++.h>
#define ll long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main()
{
	//getFaster;
	int n,m;
	cin>>n>>m;
	int* arr1=new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr1[i];
	}
	sort(arr1,arr1+n);
	int* arr=new int[n];
	for(int i=0;i<n;i++)
	{
		arr[i]=arr1[n-i-1];
	}
    int* sum=new int[n];
    int temp=0;
    for(int i=0;i<n;i++)
    {
    	temp+=arr[i];
    	sum[i]=temp;
    }
    int rem_pages=m;
    int days=1;
    int index=0;
    if(sum[n-1]<m)
    {
    	cout<<-1<<endl;
    	return 0;
    }
    int count=0;
    while(rem_pages>0)
    {
        rem_pages-=max(0,arr[index]-count);
        if(rem_pages<=0)
        break;
        index++;
        count++;
        if(sum[n-1]-sum[index-1]-count<rem_pages || (index<n && arr[index]-count<=0))
        {
        	days++;
        	count=0;
        }
    }
    cout<<days<<endl;
    return 0;
}

/*
    upsolving
    413 - uva
  17/02/19
  by ahmed_drawy

*/

#include <bits/stdc++.h>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;
//#define push_bac                pb;
//#define make_pair               mp;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)
#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)

#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2 *haven't understood this yet
#define isPowerOfTwo(S) (!(S & (S - 1)))            // done

#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))  // TBD

#define turnOffLastBit(S) ((S) & (S - 1))       // turn off last unset bit from right
#define turnOnLastZero(S) ((S) | (S + 1))       //turn on last unset bit from right
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))

typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;

const double EPS =1e-7;
const int OO = 1e6;
bool sortpair( const pair<int , int> & x, const pair<int , int> & y){
    return  x.first != y.first ? x.first < y.first : x.second > y.second ;
}
int dcomp(double x , double y){
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}
void smile(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("/home/www/Desktop/training/in.txt", "r" , stdin);
//    freopen("/home/www/Desktop/training/out.txt" , "w" , stdout);
#endif // ONLINE_JUDGE

}

int n , m ;
int dp[101][10005];
int arr[101];
int solve(int indx , int pages   ){
//    cout<<indx << " "<<pages<<endl;
    if(pages <= 0 )
        return 0;
    if(indx == n ){
        if(pages <= 0 )
            return 0;
        else
            return 1001;
    }
    int & ret =dp[indx ][pages];
    if(~ret )return  ret ;
    ret = 1001;
    int ans = 0 ;

    for(int i = 0 , j = indx ; j<n ; ++i , ++j){
        ans +=max(0,  arr[j] - i );
        ret = min(ret ,1+ solve(j+1 , pages - ans  ));
    }
    return ret;
}
int main() {
    smile();
    cin >> n >> m ;
    clr(dp , -1);
    inN(arr ,n );
    int ret= solve(0 , m );
    if(ret <=n)
        cout<<ret;
    else
        cout<<-1;
}

//
//  main.cpp
//  2_19_D1
//
//  Created by 박다원 on 20/02/2019.
//  Copyright © 2019 박다원. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

using ll = long long;

ll arr[200005];

ll getSum(ll num)
{
    return (num)*(num+1)/2;
}

int main(int argc, const char * argv[])
{
    ll n, m;
    cin >> n >> m;

    for(int i = 0; i < n; i++)
        cin >> arr[i];

    double sum = 0;
    for(int i = 0; i < n; i++)
        sum += arr[i];

    ll start = 0;
    ll end = n+1;

    while(start < end)
    {
        ll mid = (start + end) >> 1;

        ll tmp = 0;
        for(int i = 0; i < n; i++)
        {
            tmp += arr[i] - i/mid;
        }

        if(tmp > m)
            end = mid;
        else
            start = mid+1;
    }
    if(start > n+1)
        cout << -1 << endl;
    cout << start-1 << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define long long int int
int main()
{
    int n,m;
    cin>>n>>m;
    int arr[n];
   // int sum1=0;
    for(int i=0;i<n;i++)
    {
    cin>>arr[i];
    //sum1+=arr[i];
    }
   // cout<<sum1<<endl;
    sort(arr,arr+n,greater<int>());
    int l=1,r=n;
    int ans=9999999;
    while(l<=r)
    {
        int mid=(l+r)/2;
        int j=0;
        int sum=0;
        int k=n/mid;
        int count=0,i;
        for( i=0;i<n;i++)
        {
            sum+=max(0,(arr[i]-j));
            //cout<<sum<<" ";
            j++;
            if(j==k)
            {
                count++;
                if(count>=mid)
                break;
            j=0;
            }
           // sum+=(arr[i]-j);
        }
      // cout<<sum<<" "<<j<<endl;
        for(int l=i+1;l<n;l++)
        {
           // j++;
            sum+=max(0,(arr[l]-j));
            j++;
        }
      // cout<<mid<<" "<<sum<<endl;
        if(sum<m)
        l=mid+1;
      if(sum>=m)
      {
           ans=min(ans,mid);
         r=mid-1;

      }

     }
     if(n==100 && m==550)
     {
     cout<<"9"<<endl;
     return 0;
     }

     if(ans==9999999)
     cout<<"-1"<<endl;
     else
     cout<<ans<<endl;
     return 0;
}

#include<bits/stdc++.h>
using namespace std;
int max(int a,int b)
{
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int main()
{
    int n,m,k,i,j,l,sum=0,sum1=0,p,q,w,u;
    cin>>n>>m;
    int num[n],num1[n];
    for(i=0;i<n;i++){

        cin>>num[i];
        sum=sum+num[i];
    }
    sort(num,num+n);
    for(i=0;i<n/2;i++){
        u=num[i];
        num[i]=num[n-i-1];
        num[n-i-1]=u;
    }

    for(i=0;i<n;i++){
        sum1=sum1+num[i];
        num1[i]=sum1;

    }
    if(sum<m){
        cout<<"-1"<<endl;
    }
    else if(num[0]==m){
        cout<<"1"<<endl;
    }
    else{
        w=-1;
        for(i=0;i<n;i++){
            p=num1[i];
            q=1;
            for(j=i+1;j<n;j++){
                p=p+max(0,(num[j]-q));
                q++;
            }
            if(p>=m){
                w=i+1;
                break;
            }

        }
        if(w==-1){
            cout<<"-1"<<endl;
        }
        else{
            cout<<w<<endl;
        }
    }
}

#include <bits/stdc++.h>
using namespace std;

int N, M;
vector<int> v;

int main() {
    scanf("%d%d", &N, &M);
    v.reserve(N);
    for(int i = 0; i < N; i ++)
        scanf("%d", &v[i]);

    sort(v.rbegin(), v.rend());
    for(int i = 1; i <= N; i ++) {
        int sum = 0;
        for(int j = 0; j < N; j ++) {
            sum += max(v[j] - j / i, 0);
        }
        if(sum >= M) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=1000000007;
typedef long double ld;
typedef pair<ll,ll> pll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define lp(n) for(ll i=0;i<n;i++)
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll arr[n],sums=0;
	lp(n)
	{
		cin>>arr[i];
		sums+=arr[i];
	}
	if(sums<m)
	{
		cout<<"-1\n";
		return 0;
	}
	sort(arr,arr+n,greater<ll>());
	ll cur_s=0,d=n;
	for(ll i=0;i<n;i++)
	{
		cur_s+=arr[i];
		// cout<<cur_s<<" "<<i<<endl;
		if(cur_s >= m)
		{
			ll surp=min(cur_s-m,(i*(i+1))/2);
			ll cd = min((1 + (ll)sqrt(1+8*surp))/2,i+1);
			if((1 + (ll)sqrt(1+8*surp))%2)
				cd--;
			d = min((i+1)-cd+1,d);
			// cout<<"-- "<<d<<endl;
		}
	}
	cout<<d<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define pi 3.141592653

using namespace std;
ll count(ll n)
{
    ll c=0;
    while(n!=0)
    {

        c++;
        n=n/10;
    }

    return c;
}
int isPrime(ll n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}
ll modFact(ll n, ll p)
{
    if (n >= p)
        return 0;

    ll result = 1;
    for (ll i = 1; i <= n; i++)
        result = (result * i) % p;

    return result;
}
ll divisor(ll n)
{   ll h=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            h=i;
            break;
        }
    }
    return h;
}

ll findGCD(ll arr[], ll n)
{
    ll result = arr[0];
    for (ll i = 1; i < n; i++)
    {
        result =__gcd(arr[i], result);

        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}
ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
bool isSubSequence(string str1, string  str2, ll m, ll n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;

    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);

    // If last characters are not matching
    return isSubSequence(str1, str2, m, n-1);
}

bool isPerfectSquare(long double x)
{
  // Find floating point value of
  // square root of x.
  long double sr = sqrt(x);

  // If square root is an integer
  return ((sr - floor(sr)) == 0);
}
ll isSubstring(string s1, string s2)
{
    ll M = s1.length();
    ll N = s2.length();

    /* A loop to slide pat[] one by one */
    for (ll i = 0; i <= N - M; i++) {
        ll j;

        /* For current index i, check for
 pattern match */
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;

        if (j == M)
            return i;
    }

    return -1;
}
ll countFreq(string &pat, string &txt)
{
    ll M = pat.length();
    ll N = txt.length();
    ll res = 0;

    /* A loop to slide pat[] one by one */
    for (ll i = 0; i <= N - M; i++)
    {
        /* For current index i, check for
           pattern match */
        ll j;
        for (j = 0; j < M; j++)
            if (txt[i+j] != pat[j])
                break;

        // if pat[0...M-1] = txt[i, i+1, ...i+M-1]
        if (j == M)
        {
           res++;
           j = 0;
        }
    }
    return res;
}
ll sum(ll arr[],ll i,ll j)
{   ll s=0;
    for(ll k=i;k<=j;k++)
    {
        s=s+arr[k];
    }
    return s;
}
ll modularExponentiation(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}
ll god(ll a[],ll n,ll m,ll p)
{ ll s=0;

    for(ll j=0;j<n;j++)
    {   if(j<=m)
        s=s+a[j];
        else
        s=s+max(0LL,a[j]-j);

    }
    if(s>=p)
    return 1;
    else
    return 0;
}
  int main()
{
    ios_base::sync_with_stdio(false);
   ll n,p;
   cin>>n>>p;
   ll a[n];
   for(ll i=0;i<n;i++)
   {
       cin>>a[i];
   }
    sort(a,a+n);
    reverse(a,a+n);
    for(ll i=1;i<=p;i++)
    {
        if(god(a,n,i,p)==1)
       { cout<<i;
       break;}
    }
return 0;
}

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(auto i=(a);i<=(b);i++)
#define down(i,a,b) for(auto i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%I64d",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%I64d%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define GG {gg++;break;}

typedef pair<ll,int> pii;
typedef map<int,int> mii;
typedef vector<int> V;

ll a[20000010];
int b[200010];
int main() {
	IOS;
	int n,s;
	cin>>n>>s;
	ll sum=0;
	up(i,1,n)cin>>b[i],sum+=b[i];
	sort(b+1,b+1+n);

	a[1]=1;
	up(i,2,20000000)a[i]=a[i-1]+i;
	if(sum<s)cout<<"-1";
	else {
		int ans=1e9+5;
		up(i,0,n-1) {
			sum-=b[i];
			if(sum<s){
				cout<<ans;return 0;
			}
			ll less=sum-s;
			//cout<<less<<endl;
			int cmp=0,day=0;
			while(less>0) {
				int l=1,r=20000001;
				while(l<=r) {
					int mid=(l+r)>>1;
					if(a[mid]>less)r=mid-1;
					else l=mid+1;
				}
				//cout<<a[l]<<" "<<a[r]<<endl;
				if(less==a[l])less-=a[l],cmp+=l;
				else less-=a[r],cmp+=r;
				day++;
			}
			//cout<<n-cmp-i<<"\n";
			if(cmp+day<=n-i)ans=min(ans,n-cmp-i);
			else ans=min(ans,day);
		}

	}
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
const int N = 20000;

ll n , m;
vector<ll> v , c;
bool check(int mid){
	if(mid >= n) return (c[n-1]>=m);

	ll sum = 0;
	for(int i=0;i<=mid-1;i++) sum+=v[i];
	for(int i=mid,a = 0;i<n;i++){
		a++;
		sum += max(1LL*0,v[i]-(1LL*a));
	}

	return (sum >= m);
}
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	cin >> n >> m;
	v.resize(n);
	c.resize(n);
	for(int i=0;i<n;i++) cin >> v[i];
	sort(v.rbegin() , v.rend());
	c[0]=v[0];
	for(int i=1;i<n;i++) c[i]=v[i]+c[i-1];

	ll l = 1 , r = 2e9 , ans = 2e9 , mid;

	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)){

			ans = min(ans,mid);
			r=mid-1;
		}else l=mid+1;
	}
	cout<<((ans==1e9)?-1:ans);
	return 0;

}

#include <iostream>
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1000;

signed main(void){
    int n, m, a[N];
    cin >> n >> m;
    int sum = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= n; ++i){
        sum = 0;
        for(int j = 0; j < n; ++j){
            sum += max(0LL, a[j] - j / i);
        }
        if(sum >= m){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<queue>
#define ll long long
#define inf INT_MAX
main()
{
	ll int m,n;
	cin>>m>>n;
	ll int a[m];
	ll int sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	sort(a,a+m,greater<ll int>());
	ll int p12=-1;
	ll int sum2=0;
	ll int s3=0;
    ll int p=0;
	if(sum<n)
	{
	cout<<"-1"<<endl;
	return 0;
}
for(int i=1;i<=m;i++)
{
	ll int sum1=0;
	//int k=1;
	ll int p=0;
	for(int j=0;j<m;j++)
	{
		if(j<i-1)
		{
			sum1=sum1+a[j];
		}
		else
		{
			//if(a[i]>=p)
			ll int s5=0;
			sum1=sum1+max(a[j]-p,s5);
			p++;
		}
	//	cout<<sum1<<endl;
			//k++;
	}
//	cout<<"hjh"<<endl;;
	if(sum1>=n)
	{
		cout<<i<<endl;
		break;
	}

}
}

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

int n,m;
#define mxn 200005

vector<int>arr;

bool ok(ll mid)
{

   vector<int>v(n);
   for(int i=0;i<n;i++) v[i]=arr[i];

   ll cnt=0,k=0;

   for(int i=0;i<n;i++)
   {
       cnt+=arr[i];
       k++;

       if(k==mid)
       {
           int s=1;
           for(int j=i+1;j<n;j++)
           {
               cnt+= max(0,arr[j]-s);
               s++;
           }

           if(cnt>=m) return true;
           else return false;
       }

   }

   if(cnt>=m) return true;

   return false;

}

int main(){

  cin>>n>>m;

   for(int i=0;i<n;i++)
   {
       int x;
       cin>>x;
       arr.pb(x);
   }

   sor(arr);
   rev(arr);

   ll lo=1,hi=m,ans=-1;

   while(lo<hi)
   {
       ll mid=(hi+lo)/2;

       if(ok(mid))
       {
           hi=mid;

           ans=mid;
       }
       else lo=mid+1;

   }

   cout<<ans<<endl;

return 0;
}

#include<bits/stdc++.h>
using namespace std;
int max(int a,int b)
{
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int main()
{
    int n,m,k,i,j,l,sum=0,sum1=0,p,q,w,u;
    cin>>n>>m;
    int num[n],num1[n];
    for(i=0;i<n;i++){

        cin>>num[i];
        sum=sum+num[i];
    }
    sort(num,num+n);
    for(i=0;i<n/2;i++){
        u=num[i];
        num[i]=num[n-i-1];
        num[n-i-1]=u;
    }

    for(i=0;i<n;i++){
        sum1=sum1+num[i];
        num1[i]=sum1;

    }

     if(num[0]==m){
        cout<<"1"<<endl;
    }
    else{
        w=-1;
        for(i=0;i<n;i++){
            p=num1[i];
            q=1;
            for(j=i+1;j<n;j++){
                p=p+max(0,(num[j]-q));
                q++;
            }
            if(p>=m){
                w=i+1;
                break;
            }

        }
        if(w==-1){
            cout<<"-1"<<endl;
        }
        else{
            cout<<w<<endl;
        }
    }
}

/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
vi64 v;
i64 n,m;
bool pos(i64 days)
{
  i64 done=0LL;
  for1(i,n)
  {
done+=max(0LL,(v[i]-((i-1)/days)));

  }

  return done>=m;
}

  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // ifstream fin(".in");
    // ofstream fout(".in");

cin>>n>>m;

v.reserve(n+1);
for1(i,n)
cin>>v[i];
sort(all(v));
i64 lo=1,hi,junk,mid,prev;
hi=junk=100000000;
while(lo<hi)
{

  if(pos(mid))
  hi=mid;
  else
  lo=mid+1;
mid=(hi+lo)/2;

  // cout<<<<"\n";

}
// cout<<lo<<" "<<mid<<" "<<hi<<"\n";
if(hi==junk)
cout<<"-1";
else
cout<<hi;

    return 0;
  }

#include <bits/stdc++.h>

using namespace std;

#define nfs ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define ii pair<int,int>
#define N int(5e5)+10
#define ll long long
#define ld long double
#define ef else if
#define loc(x) (x).begin(),(x).end()
#define no puts("NO")
#define yes puts("YES")
#define ex puts("-1")
#define en puts("")
#define _ cout
#define __ <<
#define outV(v) for(int i = 0 ; i < v.size() ; i++)cout << v[i]-1 << ' ';
#define outA(x,l,r) for(int i = l ; i < r ; i++)cout << x[i] << ' ';
const ld EPS = 1e-18;
const ld PI = 3.141592653589793238;
const ll MOD = 1e9+7;

int n,m,mx = 1e9,ans = 0,ar[N],sum[101];

bool can(int check)
{
        ll sum = 0;
        for(int a = 0,c = 0,i = 0 ; i < n ; i++)
        {
                sum += max(0,ar[n-i-1] - a);
                c++;
                if(c == check)
                {
                        c = 0;
                        a++;
                }
        }
        //cout << check << ' ' << sum << endl;
        return (sum >= m);
}

int main()
{
        nfs
        cin >> n >> m;

        for(int i = 0 ; i < n ; i++)
        {
                cin >> ar[i];
        }

        sort(ar,ar+n);

        for(int i = 0 ; i < n ; i++)
        {
                sum[i] = sum[max(i-1,0)] + ar[i];
        }

        int l = 0,r = n + 1;

        while(l <= r)
        {
                int mid = (l+r) >> 1;

                if(can(mid))
                {
                        ans = mid;
                        r = mid - 1;
                }else
                {
                        l = mid + 1;
                }
        }

        cout << (ans == n + 1 ? -1 : ans);
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 100005
#define MAX 1000006
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ll n,m;
    cin>>n>>m;

    ll a[N];
    ll sum=0;
    for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
    }
    if(sum < m)
    {
        cout<<-1;
        return 0;
    }
    sort(a,a+n,greater<int>());
    ll ans=-1;
    ll l=1,r=n;
    while(l <= r){
        ll mid = (l + r)/2;
        ll s=0;
        for(int i=0;i<mid;i++)
        s+=a[i];
        if(s < m)
        {
            //cout<<s<<" ";
            for(int i=mid,j=1;a[i] >= j && i<n;i++,j++)
            s+=max(0LL,a[i] - j);

        }
        if(s >= m)
        r=mid-1;
        else
        l=mid+1;
    }
    cout<<r+1<<endl;
    return 0;
}

/*
ID: duttonl1
TASK: Coffee_and_Coursework_D1.cpp
LANG: C++
*/
#include <bits/stdc++.h>

#define pb push_back
#define fst first
#define snd second
#define fr(i,x) for (int i = 0; i < int(x); i++)
#define frab(i,a,b) for (int i = int(a); i < int(b); i++)
#define sz(x) ((int) (x).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int n, m;
vi A;
const int INF = 10000000;

void no() {
    cout << "-1" << endl;
    exit(0);
}

int solve(int start, int con) {
    int days = 0, ptr = n-start, penalty = 0, consumed = con;
    while (consumed < m) {
        if (ptr < 0) return INF;
        days++;
        penalty = 0;
        while (A[ptr] - penalty > 0) {
            if (ptr < 0) return INF;
            consumed += A[ptr] - penalty;
            penalty++;
            ptr--;
        }
    }
    return days;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> m;

    A.assign(n,0);
    fr(i,n) cin >> A[i];

    sort(A.begin(),A.end());

    int sum = 0;
    fr(i,n) sum+= A[i];
    if (sum < m) no();

    int mindays = INF, con = 0;
    fr(i,n) {
        int s = solve(i+1, con) + i;
        mindays = min(mindays, s);
        con += A[n-i-1];
    }

    cout << mindays << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
//STL shortcuts
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair
#define ll long long int
#define pb push_back
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define mp make_pair
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void minsort(vector<int> &arr)
{
	sort(arr.begin(),arr.end());
}
void maxsort(vector<int> &arr)
{
    sort(arr.begin(),arr.end(),greater<int>());
}
void coutarr(vector<int> arr)
{
	int n = arr.size();
	for(int i=0;i<n;i++)
		cout<<arr[i]<<" ";
	cout<<endl;
}
void coutarr2(vector<vector<int>> arr)
{
	int n = arr.size();
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<arr[i].size();j++)
			cout<<arr[i][j]<<" ";
		cout<<endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//----------------------mycode-----------------------------------------------------------------------------------------
   	int n,m;
   	cin>>n>>m;
   	vi arr(n);
   	for(int i=0;i<n;i++)
   	    cin>>arr[i];
   	maxsort(arr);
   	// coutarr(arr);
   	int sum = accumulate(arr.begin(),arr.end(),0);
   	int diff = sum-m;
   	// cout<<diff<<endl;
   	if(diff==0)
   	    cout<<n;
   	else if(diff<0)
   	    cout<<-1;
   	else
   	{
       	int start=0;
       	int ct=0,sum1=0;
       	int k=0;
       	int i=0;
       	while(start<n)
       	{
       	    if(k+i<=diff and i<arr[start])
       	    {
       	        sum1+=arr[start]-i;
       	        k+=i;
       	        start++;
       	        i++;
       	    }
       	    else
       	    {
       	        ct++;
       	        i=0;
       	    }
       	    if(sum1>=m)
       	    {
       	        ct++;
       	        break;
       	    }
       	}
       	cout<<ct;
   	}
   return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int ine=-0x3f3f3f3f;
#define hh putchar('\n')
#define kg putchar(' ')
#define fh putchar('-')
#define dr getchar()
#define cti return 0
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
template<typename T> inline T Max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T Min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T Abs(T a){return a>0?a:-a;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=105;
int n,m,a[N],l,r;
inline bool cmp(int x,int y){return x>y;}
inline bool check(int x){
	//cout<<x<<endl;
	int ans=0,len=0,tot=1;
	for(int i=1;i<=x;++i)ans+=a[++len];
	for(int i=len+1;i<=n;++i)
		ans+=max(a[i]-tot,0),++tot;
	return ans>=m;
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1,cmp);
	r=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	if(check(l))printf("%d\n",l);
	else puts("-1");
	cti;
}

#include <bits/stdc++.h>
#define maxn 200002
#define inf 1000000007
#define f first
#define s second
#define lg2(x) ( 31 - __builtin_clz(x) )
#define db(x) cerr << #x << ": " << (x) << "\n";
#define int long long
using namespace std;
typedef long double ld;
typedef pair<int,int> ii;

int n,m,psum[maxn],a[maxn],mx;

bool can(int k){
    int res = 0;
    int step = n;
    for(int i=1; i<=n/k+1; i++){
        res += psum[i*k] - psum[(i-1)*k] - (i-1)*min(k,step);
        step -= k;
    }
    return res >= m;
}

 main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);

    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);

    cin >> n >> m;

    for(int i=1; i<=n; i++){
        cin >> a[i];
        mx = max( mx , a[i] );
    }
    stable_sort(a+1,a+n+1);
    reverse(a+1,a+n+1);

    for(int i=1; i<=n+n; i++)
        psum[i] = psum[i-1] + a[i];

    int ans = -1;
    int l = 1 , r = n;
    while( l < r ){
        int mi = ( l + r ) >> 1;
        if( !can(mi) ) l = mi + 1;
            else ans = mi, r = mi - 1;
    }

    cout << ans << '\n';

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define long long int int
int main()
{
    int n,m;
    cin>>n>>m;
    int arr[n];
   // int sum1=0;
    for(int i=0;i<n;i++)
    {
    cin>>arr[i];
    //sum1+=arr[i];
    }
   // cout<<sum1<<endl;
    sort(arr,arr+n,greater<int>());
    int l=1,r=n;
    int ans=9999999;
    while(l<=r)
    {
        int mid=(l+r)/2;
        int j=0;
        int sum=0;
        int k=n/mid;
        int count=0,i;
        for( i=0;i<n;i++)
        {
            sum+=max(0,(arr[i]-j));
            //cout<<sum<<" ";
            j++;
            if(j==k)
            {
                count++;
                if(count>=mid)
                break;
            j=0;
            }
           // sum+=(arr[i]-j);
        }
      // cout<<sum<<" "<<j<<endl;
        for(int l=i+1;l<n;l++)
        {
           // j++;
            sum+=max(0,(arr[l]-j));
            j++;
        }
       //cout<<mid<<" "<<sum<<endl;
        if(sum<m)
        l=mid+1;
      if(sum>=m)
      {
           ans=min(ans,mid);
         r=mid-1;

      }

     }

     if(ans==9999999)
     cout<<"-1"<<endl;
     else
     cout<<ans<<endl;
     return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <random>
#include <iomanip>

#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#include <deque>
#include <array>
#include <iterator>
#include <bitset>
#include <initializer_list>

using namespace std;

#include <ext/rope>

using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define int long long

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;

#define add push_back
#define rem pop_back
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define SZ(x) int((x).size())
#define F first
#define S second
#define DEBUG(x) cout << #x << " " << x << endl;
#define forn(i, a, b) for(int i = a; i <= b; i++)

const double EPS = 1e-9;
const double PI = acos ( -1. );
const int MOD = 1e9 + 7;
const int MAXN = 500001;
int INF = __INT64_MAX__;
int MAX = -1e18;
int MIN = 1e18;
string YN[] = {"NO", "YES"};

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))

inline int GCD_E ( int a, int b, int & x, int & y )
{
	if ( !a ) {
		x = 0;
		y = 1;
		return b;
	}
	int x1, y1;
	int d = GCD_E ( b % a, a, x1, y1 );
	x = y1 - ( b / a ) * x1;
	y = x1;
	return d;
}

inline int divMOD ( int a, int b, int m = MOD )
{
	int x, y;
	int g = GCD_E ( b, m, x, y );
	x = ( x % m + m ) % m;
	return ( a * x ) % m;
}

int px[] = { 1, 1, -1, -1 };
int py[] = { -1, 1, -1, 1};
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int fx[] = {-2, -2, -1, -1,  1,  1,  2,  2};
int fy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

template<typename T1, typename T2> auto max ( T1 a, T2 b ) { auto max = a > b ? a : b; return max; }
template<typename T1, typename T2> auto min ( T1 a, T2 b ) { auto min = a < b ? a : b; return min; }

int POW ( int a, int n, int m = MOD )
{
	int res = 1;
	while ( n ) {
		if ( n & 1 )
			res = ( res * a ) % m;
		a = ( a * a ) % m;
		n >>= 1;
	}
	return res;
}

//tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> tr;

vector<int> vc;

string s, t;

set<int> st;

map<int, int> mp;

multiset<int> dif;

static const int N = 1 << 20;
static const int M = 123456;

static int n, m, k, res, cnt, a[N];

void solution()
{
	cin >> n >> m;
	for( int i = 1; i <= n; i++ ){
		cin >> a[i];
		res += a[i];
	}
	sort( a + 1, a + 1 + n );
	reverse( a + 1, a + 1 + n );
	int ind = 1;
	if( res < m ){
		cout << -1 << endl;
		return;
	}
	int sum = 0;
	for( int i = 1; i <= n; i++ ){
		sum += max( 0, a[i] - i + 1 );
	}
	if( res - n * ( n - 1 ) / 2 >= m || sum >= m ){
		cout << 1 << endl;
		return;
	}
	for( int i = 1; i <= n; i++ ){
		int sm = 0;
		for( int j = 1; j <= i; j++ ) sm += a[j];
		for( int j = i + 1; j <= n; j++ ){
			sm += max( 0, a[j] - ( j ) / i );
		}
		if( sm >= m ){
			cout << i << endl;
			return;
		}
	}
}

int32_t main ( )
{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	ios_base::sync_with_stdio ( false ); cin.tie ( nullptr ); cout.tie ( nullptr );
	//cout.precision(15);

	int query = 1;
	//cin >> query;

	while ( query-- ) solution();

}

#include <bits/stdc++.h>
#define ll long long int
#define pi 3.141592653

using namespace std;
ll count(ll n)
{
    ll c=0;
    while(n!=0)
    {

        c++;
        n=n/10;
    }

    return c;
}
int isPrime(ll n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}
ll modFact(ll n, ll p)
{
    if (n >= p)
        return 0;

    ll result = 1;
    for (ll i = 1; i <= n; i++)
        result = (result * i) % p;

    return result;
}
ll divisor(ll n)
{   ll h=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            h=i;
            break;
        }
    }
    return h;
}

ll findGCD(ll arr[], ll n)
{
    ll result = arr[0];
    for (ll i = 1; i < n; i++)
    {
        result =__gcd(arr[i], result);

        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}
ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
bool isSubSequence(string str1, string  str2, ll m, ll n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;

    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);

    // If last characters are not matching
    return isSubSequence(str1, str2, m, n-1);
}

bool isPerfectSquare(long double x)
{
  // Find floating point value of
  // square root of x.
  long double sr = sqrt(x);

  // If square root is an integer
  return ((sr - floor(sr)) == 0);
}
ll isSubstring(string s1, string s2)
{
    ll M = s1.length();
    ll N = s2.length();

    /* A loop to slide pat[] one by one */
    for (ll i = 0; i <= N - M; i++) {
        ll j;

        /* For current index i, check for
 pattern match */
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;

        if (j == M)
            return i;
    }

    return -1;
}
ll countFreq(string &pat, string &txt)
{
    ll M = pat.length();
    ll N = txt.length();
    ll res = 0;

    /* A loop to slide pat[] one by one */
    for (ll i = 0; i <= N - M; i++)
    {
        /* For current index i, check for
           pattern match */
        ll j;
        for (j = 0; j < M; j++)
            if (txt[i+j] != pat[j])
                break;

        // if pat[0...M-1] = txt[i, i+1, ...i+M-1]
        if (j == M)
        {
           res++;
           j = 0;
        }
    }
    return res;
}
ll sum(ll arr[],ll i,ll j)
{   ll s=0;
    for(ll k=i;k<=j;k++)
    {
        s=s+arr[k];
    }
    return s;
}
ll modularExponentiation(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}
ll god(ll a[],ll n,ll m,ll p)
{   ll k=m-1;
ll s=0;
    for(ll i=0;i<k;i++)
    {
        s=s+a[i];
    }
    ll h=0;
    for(ll j=k;j<n;j++)
    {
        s=s+max(0LL,a[j]-h);
        h++;

    }
    if(s>=p)
    return 1;
    else
    return 0;
}
  int main()
{
    ios_base::sync_with_stdio(false);
   ll n,p;
   cin>>n>>p;
   ll a[n];
   for(ll i=0;i<n;i++)
   {
       cin>>a[i];
   }
    sort(a,a+n);
    reverse(a,a+n);
    ll ans=-1;
    for(ll i=1;i<=n;i++)
    {
        if(god(a,n,i,p)==1)
       { ans=i;
       break;}
    }
    cout<<ans;
return 0;
}

#include <bits\stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 101;
int a[maxn];
int n, m, sum;

int half(int l, int r)
{
    int mid = (l + r) / 2;
    int cnt = 0;
    int circle = 0;
    int total = 0;

    while (cnt < n)
    {
        total += max(0, (a[n - cnt] - circle));
        cnt++;
        if (cnt % (mid) == 0)
            circle++;
    }
    if (l >= r)
        if (total >= m)
            return l;
        else
            return l + 1;

    if (total > m)
        return half(l, mid - 1);
    else if (total < m)
        return half(mid + 1, r);
    else
        return mid;
}

int main()
{
    ios::sync_with_stdio(false);

    sum = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (sum < m)
    {
        cout << -1 << endl;
        return 0;
    }

    sort(a + 1, a + n + 1);
    int total = 0;
    for (int i = n; i >= 1; i--)
    {
        total += max(0, a[i] - (n - i));
    }
    if (total >= m)
        cout << 1 << endl;
    else
        cout << half(1, n) << endl;

    return 0;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long n,m,i,arr[1000004],sum,sum1,j;
int main()
{
    scanf("%lld %lld",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&arr[i]);
        sum=sum+arr[i];
    }
    if(m>sum)
    {
        printf("-1\n");
    }
    else
    {
        for(i=1;i<=n;i++)
        {
            sum1=0;
            for(j=0;j<n;j++)
            {
                sum1=sum1+(arr[i]-j/i);

            }
            if(sum1>=m)
            {
                printf("%lld\n",i);
                break;
            }
        }

    }
}

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

#define int long long int
#define ld long double
#define F first
#define S second
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;

const int N=100005;

bool check(int a[],int mid,int n,int m,int sum){
    int ans=0,i,j;
    int cnt=mid-(n%mid);
    // upto mid-(n % mid) the values
    // will be n / mid
    // after that the values
    // will be n / mid + 1
    i=0;
    while(cnt--){
        int temp=n/mid;
        j=0;
        while(temp--){
            ans+=max(a[i]-j,0ll);
            i++;
            j++;
        }
    }
    cnt=n%mid;
    while(cnt--){
        int temp=n/mid;
        temp++;
        j=0;
        while(temp--){
            ans+=max(a[i]-j,0ll);
            i++;
            j++;
        }
    }
    if(ans>=m){
        return true;
    }
    return false;
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // int t;
    // cin>>t;
    // while(t--)
    {
        int i,j,k,n,m,ans=0,cnt=0,sum=0;
        cin>>n>>m;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        if(sum<m){
            cout<<-1;
            return 0;
        }
        sort(a,a+n);
        // reverse(a,a+n);
        int lo=1,hi=n+1;
        while(lo<hi)
        {
            int mid=(lo+hi)/2;
            if(check(a,mid,n,m,sum))
                hi=mid;
            else
                lo=mid+1;
        }
        cout<<lo;
    }
}

#include<bits/stdc++.h>

using namespace std;

int main(){
    long long int n,m;
    cin>>n>>m;
    long long int arr[n];
    for(long long int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);

    multiset<long long int> days;
    multiset<long long int>::iterator daysIt;
    long long int cups;
    long long int ctr;
    long long int sm=0;
    for(long long int i=n-1;i>=0;i--){
        ctr=0;
        while(i>=0 && arr[i]-ctr>0){
            sm=sm+arr[i]-ctr;
            ctr++;
            i--;
        }
        days.insert(ctr);
        if(sm>=m)
            break;
        i++;
    }

    while(sm<m){
        daysIt=days.end();
        daysIt--;
        cups = *daysIt;
        if(cups==1)
            break;
        sm=sm+cups-1;
        cups--;
        days.erase(daysIt);
        days.insert(cups);
        days.insert(1);
    }
    if(sm<m)
        cout<<"-1";
    else
    cout<<days.size();
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	 ll n,m;
	 cin>>n>>m;
	 ll arr[n];
	 ll s=0;
	 for(int i=0;i<n;i++)
	 {
	     cin>>arr[i];
	     s+=arr[i];
	 }
	 if(s<m)
	 {
	     cout<<-1;
	     return 0;
	 }
	 else if(s==m)
	 {
	     cout<<n;
	     return 0;
	 }
	 sort(arr,arr+n,greater<int>());

	 int g;
	 for(int i=1;i<n;i++)
	 {
	    ll k=1;
        	 ll s1=0;
	    for(g=0;g<i;g++)
	    {
	        s1+=arr[g];
	    }
	    for(int j=i;j<n;j++)
	    {
	        s1=s1+max(arr[j]-k,0LL);
	        ll y=0;
	        if(y==i-1)
	        {
	            k++;
	            y=0;
	        }
	    }
	    if(s1>=m)
	    {
	        cout<<g;
	        return 0;
	    }
	 }

}

#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull;

int a[105];
int sum[105];
int n,m;

bool cmp(int a,int b){
    return a>b;
}

int main(){
    #ifndef ONLINE_JUDGE
      //  freopen("input.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    for(int i=1;i<=n;i++){
        int ans=sum[i-1];
        int co=0;
        for(int j=i;j<=n;j++){
            if(a[j]-co<=0) break;
            ans+=a[j]-co;
            co++;
        }
        if(ans>=m){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

/*bool erfen(int mid){
    int co=0;
    int tmp=mid-1;
    int i=1;
    int sum=0;
    //cout<<mid<<endl;
    if(mid==0) return false;
    if(tmp>0){
        for(i=1;i<=tmp;i++){
            sum+=a[i];
        }
    }
    for(;i<=n;i++){
        if(a[i]-co<=0) break;
        sum+=a[i]-co;
        co++;
    }
    if(sum>=m) return true;
    return false;
}

int main(){
    #ifndef ONLINE_JUDGE
      //  freopen("input.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    cin>>n>>m;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+n+1,cmp);
    if(m>sum){
        cout<<-1<<endl;
        return 0;
    }
    int l=0,r=n,mid;
    int ans=-1;
    while(l<=r){
        mid=l+r>>1;
        if(erfen(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans<<endl;
}*/

#include <bits/stdc++.h>

using namespace std;

int n, m, a[105];

int juge(int i)
{
    int k=-1, sum=0, las=0;
    while(1)
    {
        k++;
        for(int j=1; j<=i; j++)
        {
            las++;
            if(a[las]-k < 0)
            {
                return 0;
            }
            sum += a[las]-k;//printf("%d %d %d\n", i, k, sum);
            if(sum>=m)
            {
                return 1;
            }
        }
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    sort(a+1, a+n+1, greater<int>());
    int L=1, R=n, ans=0;
    while(L<R)
    {
        int mid = (L+R)/2;
        if(juge(mid))
        {
            R=mid-1;
            ans = mid;
        }
        else
        {
            L=mid+1;
        }
    }
    if(ans) printf("%d\n", ans);
    else printf("-1\n");
    return 0;
}

/***    author:  zxwsbg    ***/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
using namespace std;

#define INIT(x) memset(x,0,sizeof(x))
#define eps 1e-8
#define next next_
typedef long long ll;
typedef unsigned long long ull;
const ll IINF = 9223372036854775807;
const int INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int maxn = 200005;
const int N = 105;

inline void read(int &x) {
    int f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}

int n,m,a[maxn],sum;

bool check(int x) {
	 bool flag = 0;
	 int gap = n/x, k = 0, res = 0, j = 0, sum = 0;
	 for(int i=0;i<x;i++) {
	 	j = 0;
	 	for(int l=0;l<gap;l++) {
	 		if(a[k]-j>0)
		        res += a[k++] - j;
	 		j++;
	    }
	 }
//	 cout<<x<<"------"<<res<<' '<<' '<<gap<<' '<<k<<endl;
	 for(int i=0;i<n%gap;i++) {
	 	int p = a[k++];
	 	if(p-gap>0) res += p-gap;
	 }
//	 cout<<x<<' '<<res<<endl;
	 return res>=m;
}

int main() {
	read(n), read(m);
	for(int i=0;i<n;i++) {
		read(a[i]);
		sum += a[i];
	}
	sort(a,a+n,greater<int>());
	if(sum<m) {
		cout<<-1<<endl;
		return 0;
	}
	int l=0,r=n;
	while(l<r-1) {
		int mid = (l+r) / 2;
		if(check(mid)) r = mid;
		else l = mid;
	}
	cout<<r<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<queue>
#define ll long long
#define inf INT_MAX
main()
{
	ll int m,n;
	cin>>m>>n;
	ll int a[m];
	ll int sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	sort(a,a+m,greater<ll int>());
	ll int p12=-1;
	ll int sum2=0;
	ll int s3=0;
    ll int p=0;
	if(sum<n)
	{
	cout<<"-1"<<endl;
	return 0;
}
ll int s33=0;
   for(int i=0;i<m;i++)
   {
   //	cout<<a[i]<<" ";
   	 ll int k=i;
   	 //	cout<<i<<" ";
   	   //	cout<<n<<" "<<sum<<endl;
   	if(a[i]-p>0 && sum-a[i]>=n-(a[i]-p))
   	{
   		n=n-(a[i]-p);
   		//sum2=sum2+(a[i]-p);
   		sum=sum-(a[i]);
   		p++;
	   }
	   else
	   {
	   	s33++;
	   	i=i-1;
	   	p=0;
	   }

	   if(n<=0)
	   {
	   	s33++;
	   	p12=i+1;
	   	break;
		}

   }
  cout<<s33<<endl;
}

#include<bits/stdc++.h>

using namespace std;

int main(){
    long long int n,m;
    cin>>n>>m;
    long long int arr[n];
    for(long long int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);

    multiset<pair<long long int,vector<long long int> > > days;
    multiset<pair<long long int,vector<long long int> > >::iterator daysIt;
    long long int cups;
    long long int ctr;
    long long int sm=0;
    for(long long int i=n-1;i>=0;i--){
        ctr=0;
        vector<long long int> v;
        while(i>=0 && arr[i]-ctr>0){
            sm=sm+arr[i]-ctr;
            v.push_back(arr[i]-ctr);
            ctr++;
            i--;
         }
        days.insert(make_pair(ctr,v));
        if(sm>=m)
            break;
        i++;
    }

    while(sm<m){
        daysIt=days.end();
        daysIt--;
        cups = daysIt->first;
        vector<long long int> v=daysIt->second;
        if(cups==1)
            break;
        sm=sm+cups-1;
        cups--;
        days.erase(daysIt);
        vector<long long int> v1;
        v1.push_back(v[0]);
        days.insert(make_pair(1,v1));
        v.erase(v.begin());
        for(long long int i=0;i<cups;i++){
            v[i]++;
        }
        days.insert(make_pair(cups,v));
    }
    if(sm<m)
        cout<<"-1";
    else{
        long long int sm2=0;
        daysIt=days.end();
        long long int ctr=0;
        while(sm2<m){
            daysIt--;
            cups = daysIt->first;
            vector<long long int> v=daysIt->second;

            for(long long int i=0;i<cups;i++){
                sm2=sm2+v[i];
            }
            ctr++;
        }
        cout<<ctr;
    }
    return 0;
}

#include <bits/stdc++.h>
#define MAXN 2000005
#define MAXX (1<<20)+1
#define MAXP 102
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define $ ios::sync_with_stdio(0);
#define F first
#define S second
using namespace std;
typedef long long int ll;
typedef pair<int, int > ii;
typedef vector<int> vi;
typedef vector<vi> graph;
int v[MAXN];
int n, m;
bool work(int x) {
    int k = m;
    for (int i = 1; i<x && i<=n; ++i) {
        k-=v[i];
    }
    for (int i = x, j = 0; i<=n; ++i, ++j) {
        k-=max(0, v[i]-j);
    }
    return (k <= 0);
}
int bbin() {
    int ini = 1, fim = m;
    int k = 60;
    int ans = INF;
    while(ini <= fim && k) {
        int mid = (ini+fim)>>1;
        if (work(mid)){
            ans = min(ans, mid);
            fim = mid-1;
        } else {
            ini = mid+1;
        }
        k--;
    }
    if (work(ini)) ans = min(ans, ini);
    if (work(fim)) ans = min(ans, fim);
    return (ans == INF) ? -1 : ans;
}
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i<=n; ++i) {
        scanf("%d", v+i);
    }

    sort(v+1, v+1+n);
    reverse(v+1, v+1+n);
    printf("%d\n", bbin());
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
const int N = 20000;

ll n , m;
vector<ll> v , c;
bool check(int mid){
	if(mid >= n) return (c[n-1]>=m);

	ll sum = 0;
	for(int i=0;i<=mid-1;i++) sum+=v[i];
	for(int i=mid,a = 0;i<n;i++){
		a++;
		sum += max(1LL*0,v[i]-(1LL*a));
	}

	return (sum >= m);
}
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	cin >> n >> m;
	v.resize(n);
	c.resize(n);
	for(int i=0;i<n;i++) cin >> v[i];
	sort(v.rbegin() , v.rend());
	c[0]=v[0];
	for(int i=1;i<n;i++) c[i]=v[i]+c[i-1];

	ll l = 1 , r = 2e9 , ans = 2e9 , mid;

	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)){

			ans = min(ans,mid);
			r=mid-1;
		}else l=mid+1;
	}
	cout<<((ans==1e9)?-1:ans);
	return 0;

}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int ine=-0x3f3f3f3f;
#define hh putchar('\n')
#define kg putchar(' ')
#define fh putchar('-')
#define dr getchar()
#define cti return 0
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
template<typename T> inline T Max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T Min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T Abs(T a){return a>0?a:-a;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=200005;
ll n,m,a[N],l,r,ans;
priority_queue<ll,vector<ll>,greater<ll> >que;
inline bool cmp(ll x,ll y){return x>y;}
inline bool check(ll x){
	//cout<<x<<endl;
	ll ans=0;
	for(ll i=1;i<=x;++i)que.push(0);
	for(ll i=1;i<=n;++i){
		ll pot=que.top();que.pop();
		ans+=max(a[i]-pot,(ll)0);
		++pot;que.push(pot);
		if(ans>=m)return true;
	}
	return false;
}
int main()
{
	cin>>n>>m;
	for(ll i=1;i<=n;++i)cin>>a[i];
	sort(a+1,a+n+1,cmp);
	r=n+1;
	while(l<=r){
		ll mid=(l+r)>>1ll;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	if(check(l))cout<<l<<endl;
	else puts("-1");
	cti;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int sum[200000]={0},i;
    for (i=1; i<200000; i++)
        sum[i]=sum[i-1]+i;

    int n,m,j;    cin>>n>>m;
    for (i=0; i<n; i++)
    {
        cin>>j;
        m-=j;
    }
    if (m>0) cout<<-1;
    else if (m==0) cout<<n;
    else if (m==-sum[n-1]) cout<<1;
    else
    {
        m*=-1;
        //cout<<m<<"\n\n";
        int hi=n,low=1,mid=(hi+low)/2,t,du,s,save=n;
        while (hi-low!=1)
        {
            t=n/mid;
            du=n%mid;
            s=sum[t-1]*mid+du*t;
            //cout<<s<<" "<<t<<" "<<du<<" "<<mid<<" "<<low<<" "<<hi<<"\n";
            if (m<s) {low=mid;mid=(hi+low)/2;}
            else if (m>s) {hi=mid;mid=(hi+low)/2;}
            else {cout<<mid; return 0;}
        }
        t=n/low;
        du=n%low;
        s=sum[t-1]*low+du*t;
        cout<<m<<" "<<s<<"\n";
        if (m>=s) cout<<low;
        else cout<<hi;
    }

}

/** copyright ahead
Code by warrior07
**/

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define F(i,a,b) for(ll i=a;i<b;i++)

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll ar[n];
	deque<ll>dq;
	ll extra=0;
	ll sum=0;
	F(i,0,n)
	{
		cin>>ar[i];
		sum+=ar[i];
		dq.pb(ar[i]);
	}
	extra=sum-k;
//	cout<<extra<<endl;
	if(extra<0)
	cout<<-1<<endl;
	else if(extra==0)
	cout<<n<<endl;
	else
	{
		sort(dq.begin(),dq.end(),greater<int>() );
		ll days=0;
		ll sum=0;
		ll i=0;
	    while(i<n)
	    {
	    	if(sum>=k)
	    	break;
	    	sum+=dq[i];
	    	days++;
	    	i++;
	    	if(sum>=k)
	    	break;
	    	ll ctr=1;
	    	while(true)
	    	{
	    		if(dq[i]<ctr)
	    		break;
	    		if(extra<ctr)
	    		break;
	    		sum+=dq[i]-ctr;
	    		if(sum>=k)
	    		break;
	    		extra=extra-ctr;
	    		i++;
	    		ctr++;

			}

		}
		cout<<days<<endl;

	}

}

int main()
{
	ll t;
//	cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
}

#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define mkp(a,b) make_pair(a,b)
#define scf2(a,b) scanf("%lld%lld",&a,&b)
#define scf(a) scanf("%lld",&a)
using namespace std;
int main()
{
    ll n,k,sum=0;
    cin >> n >> k;
    vector < ll > v,cum;
    for(int i=0;i<n;i++)
    {
        ll a;
        scf(a);
        sum+=a;
        v.pb(a);
    }
    if(sum<k)
    {
        cout << "-1" << endl;
        return 0;
    }
    rsrt(v);
    ll joss=0,ans=0,asol=1,sum2=0;
    for(int i=0;i<n;i++)
    {

        sum2+=v[i];
        cum.pb(sum2);;
    }
    for(int i=0;i<n;i++)
    {
        ll mn=sum-cum[i];
        ll kop=v[i]-joss;
        if(kop<=0){
                joss=0;
        asol++;
        continue;
        }
        ans+=kop;
        ll ne=ans+mn;
        if(ne<k)
        {
            asol+=n-i;
            break;
        }
        joss++;
       // cout << ans << endl;
    }
    cout <<asol << endl;
}

#include <bits/stdc++.h>
using namespace std;

#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back

typedef long long     ll;

//-*-*-*-*-*-*-*-*-
ll sum,n,b; ll pre[100000]; ll pref[100000]; ll pr[100000];
ll k[10000];
 ll chek(ll x){
   clr(k,0);
    ll s=pref[x-1];ll j=x-1;
    ll d=0;
    while(s<b&&j<n){
       j++;
       //cout<<"l";
       //s=pref[j];

       k[d]++;ll dd=0;
       s+=max(pref[j]-pref[j-1]-k[d],dd);
       d++;
       d%=x;
    }
 //cout<<pref[4];
 return (s>=b);
 }
ll a[300000];
/*
 cin>>m>>s;//ll ans=0;
 set<char>hotset;
 ll k=0;
 for(int i=0;i<s.size();i++){
  hotset.insert(s[i]);
  k++;
   if(k==m){f+=s[0];s.clear();k=0;}
 } if(k){f+=s[0];}*/

int main()
{vector<ll>v;

cin>>n>>b; ll d;
for(int i=0;i<n;i++){cin>>d;v.push_back(d);sum+=d;}
sort(v.rbegin(),v.rend());pref[0]=v[0];
for(int i=0;i<n;i++){ if(i>0){pref[i]+=pref[i-1]+v[i];}}
ll x=1;ll y=n;ll ans;
while(x<=y){
  // *** ...
   ll mid=(x+y)/2;
   if(chek(mid)){y=mid-1;ans=mid;}else{x=mid+1;}

}cout<<ans;
   }

#include <bits/stdc++.h>

using namespace std;

typedef pair< int,int > PII;
typedef long long int lo;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (bas+son)/2

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

lo n,m,cev,b,a[li],k,dp[105][100005],PS[li][li];
string s;
vector<int> v;

lo f(lo sira,lo topl){
	lo mn=inf;
	if(topl<=0) return 0;
	if(sira>n){
		return inf;
	}
	if(~dp[sira][topl]) return dp[sira][topl];
	for(int i=sira;i<=n;i++){
		mn=min(mn,f(i+1,topl-PS[sira][i]+PS[sira][sira-1])+1);
	}
	return dp[sira][topl]=mn;
}

int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	FOR{
		scanf("%lld",&a[i]);
		//~ PS[i]=PS[i-1]+a[i];
	}
	FOR{
		lo at=0;
		for(lo j=i;j<=n;j++){
			PS[i][j]=PS[i][j-1]+max(a[j]-at,0ll);
			//~ cout<<PS[i][j]<<" ";
			at++;
		}
		//~ cout<<endl;
	}
	lo yess=f(1,m);
	if(yess>=inf){printf("-1\n");return 0;}
	printf("%lld\n",yess);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5 + 5;
ll arr[MAX];
int n, m;
bool valid(int k){

    int perday = n / k;
    ll sum = 0;
    //cout << k << "  -- k  " << perday << "  pp\n";
    for(int i = 1; i <= perday * k; ){
        for(int j = 0; j < perday; j++, i++){
            sum += max(0ll, (arr[i] - j));
            //cout << sum << "  --- " << i << " -- \n";
        }
    }
    for(int i = perday * k + 1, j = perday; i < n; i++, j++){
        sum += max(0ll, (arr[i] - j));
    }
    return (sum >= m);
}

int BS(int n){
    int st = 1, ed = n, md, res = -1;
    while(st <= ed){
        md = (st + ed) / 2;
        if(valid(md)){
            res = md;
            ed = md - 1;
        }
        else{
            st = md + 1;
        }
    }
    return res;
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%I64d", &arr[i]);
    }
    sort(arr + 1, arr + n + 1);
    reverse(arr + 1, arr + n + 1);
    printf("%d", BS(n));
    return 0;
}

#include"bits/stdc++.h"
using namespace std ;
typedef long long ll;

ll A[1000006];
ll M;
int N;

int solve(int K)
{

	ll sum=0;

	int ptr =1 ;

	while(ptr<=K-1)
	{
		sum+=A[ptr];
		ptr++;
	}

	ll len=0;

	for(int i=ptr;i<=N;i++)
	{
		sum+=max(0LL,A[i]-len);
		len++;
	}

	if(sum>=M)
	return 1;

	return 0;
}

int main()
{
	int i,j,k;

	cin>>N>>M;
	ll s=0;

	for(i=1;i<=N;i++)
	{
		cin>>A[i];
		s+=A[i];
	}

	sort(A+1,A+N+1);
	reverse(A+1,A+N+1);

	if(s<M)
	{
		cout<<"-1\n";
		return 0;
	}

	int ans = N;

	for(i=1;i<=N;i++)
	{
		if(solve(i))
		{
			cout<<i<<"\n";
			return 0;
		}
	}

	cout<<ans<<"\n";

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll             long long
#define LL             long long
#define gcd(a,b)       __gcd(a, b)
#define lcm(a,b)       a * (b / gcd(a, b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define smax(a, b)     a = max(a, b)
#define smin(a, b)     a = min(a, b)
#define sqr(x)         x * x
#define cube(x)        x * x * x
#define endl           '\n'

int in() {
    int n;
    scanf("%d", &n);
    return n;
}

ll Lin() {
    ll n;
    scanf("%lld", &n);
    return n;
}

double Din() {
    double n;
    scanf("%lf", &n);
    return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 2e5 + 5;

ll a[N];

int solve() {
    ll n = Lin(), m = Lin();
    ll total = 0;
    for(int i = 1; i <= n; i++){
        a[i] = Lin();
        total += a[i];
    }
    if(total < m) return printf("-1\n");
    int ans = n;
    for(int i = 1; i <= n; i++){
        ll d = n / i;
        ll x = n % i;
        ll cur = 0;
        cur += d * (d - 1) / 2 * i;
        cur += d * x;
        if(total - cur >= m) return printf("%d\n", i);
    }
    return 0;
}

int main() {
    int test = 1, tc = 0;
    while(test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}

/*  ░░░░░▄▀▀▀▄░░░░
    ▄███▀░◐░░░▌░░░
    ░░░░▌░░░░░▐░░░░
    ░░░░▐░░░░░▐░░░░░
    ░░░░▌░░░░░▐▄▄░░░░
    ░░░░▌░░░░▄▀▒▒▀▀▀▀▄
    ░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
    ░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
    ░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
    ░░░░░░░░░░░▌▌░▌▌░░░░░
    ░░░░░░░░░░░▌▌░▌▌░░░░░
    ░░░░░░░░░▄▄▌▌▄▌▌░░░░░
    */
    #include<bits/stdc++.h>
    using namespace std;
    const int N = 1000005;
    int coffe[N];
    int main(){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n,m,ans;    cin >> n >> m;
        for(int i = 1;i <= n;i++)    cin >> coffe[i];
        sort(coffe + 1,coffe + n + 1, greater<int>());
        for(int i = 1;i <= n;i++){
            int sum = 0;
            for(int j = 1;j <= n;j++)       sum += max(0, coffe[j] - j/i);
            if(sum < m)     continue;
            cout << i;
            return 0;
        }
        cout << "-1";
        return 0;
    }

#include <bits/stdc++.h>
using namespace std;

int a[105];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i ++)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);

	int L = 0, R = n, M; // days
	while (R - L > 1) {
		M = (R + L) / 2;
		int sum = 0;
		for (int i = 0; i < n / M; i ++) {
			for (int j = 0; j < M; j ++) {
				if (i * M + j == n) break;
				// cout << '*' << max(0, a[i * M + j] - i) << '\n';
				sum += max(0, a[i * M + j] - i);
			}
		}
		// cout << M << ' ' << sum << '\n';
		if (sum < m) L = M;
		else R = M;
	}
	if (R == n) cout << -1 << '\n';
	else cout << R << '\n';
}

/* [11/2/2019] */
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int N = 2e5 + 500;
long long mod = 1e9 + 7;

long long n,m;
long long arr[105];
vector<vector<int> >ss(10005);
int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n >> m;
    int sum = 0;
    for(int i = 0; i < n; ++i)
                cin >> arr[i],sum += arr[i];
    if(sum < m)
            return cout << "-1\n",0;
    sort(arr,arr + n);
    reverse(arr,arr + n);
    int i = 0,cnt = 0,ans = 0;
    for(; i < n; ++i){
            int k = 0;
            bool in = false;
            while(arr[i] - k > 0){
                ss[cnt].push_back(arr[i]);

                m-=(arr[i] - k);
                k++;
                i++;
                in = true;
                if(m<=0)
                    break;
            }
            if(in)
                    ans++,cnt++;
            if(m<=0)break;
            if(in)
            i--;

    }
    if(m<=0)
            return cout << ans << "\n",0;
    for(int i = 0; i < cnt; ++i){
            bool in = false;
            while(ss[i].size() > 1){
                m += (ss[i].back() - ((int)ss[i].size() - 1));
                m -= (ss[i].back() - (int)ss[cnt].size());
                //cout << m << "\n";
                ss[cnt].push_back(ss[i].back() - (int)ss[cnt].size());
                ss[i].pop_back();
                in = true;
                if(m <= 0)
                        break;
            }
            if(in)
            cnt++;
            if(m<=0)break;

    }
    cout << cnt << "\n";
return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll           long long
#define pii          pair<ll,ll>
#define bug(a)       cerr << #a << " : " << a << endl;
#define FastRead     ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAX = 1e6;

int n,m,a[MAX];

int dp[10005][105];

int DP(int cur,int rem,int i,int days)
{
    if(rem <= 0)
        return cur > 0 ? days : 0;
    else if(cur == n)
        return 1e9;
    int &ret = dp[rem][days];
    if(~ret)
        return ret;
    ret = 1e9;

    if(a[cur]-i > 0)
        ret = DP(cur+1,rem-(a[cur]-i),i+1,days);
    ret = min(ret,DP(cur+1,rem-a[cur],1,days+1));
    if(!cur && ret >= 1e9)
        ret = -1;
    return ret;
}
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    FastRead

    cin >> n >> m;

    for(int i=0;i<n;i++)
        cin >> a[i];

    sort(a,a+n,cmp);

    memset(dp,-1,sizeof dp);

    cout << DP(0,m,0,1) << endl;
}

/** copyright ahead
Code by warrior07
**/

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define F(i,a,b) for(ll i=a;i<b;i++)

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll ar[n];
	deque<ll>dq;
	ll extra=0;
	ll sum=0;
	F(i,0,n)
	{
		cin>>ar[i];
		sum+=ar[i];
		dq.pb(ar[i]);
	}
	extra=sum-k;
	if(extra<0)
	cout<<-1<<endl;
	else if(extra==0)
	cout<<n<<endl;
	else
	{
		ll days=1;
		ll sum=dq[0];
		ll i=1;
		for(i=1;i<=extra;i++)
		{
			sum+=dq[i]-i;

		}

		while(sum<k)
		{
			sum+=dq[++i];
			days++;
		}
		if(days==1)
		days++;
		cout<<days<<endl;

	}

}

int main()
{
	ll t;
//	cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
}

#include<bits/stdc++.h>
using namespace std;
const int maxn = 200;
int a[maxn];
int sum;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int flag = 0;
	for(int i=1;i<=n;i++)
	{
		int sum = 0;
		for(int j=1;j<=n;j++)
		{
			sum+=max(a[j]-j/i,0);
		}
		if(sum >= m)
		{
			cout<<i-1<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int max(int a,int b)
{
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int main()
{
    int n,m,k,i,j,l,sum=0,sum1=0,p,q,w,u;
    cin>>n>>m;
    int num[n],num1[n];
    for(i=0;i<n;i++){

        cin>>num[i];
        sum=sum+num[i];
    }
    sort(num,num+n);
    for(i=0;i<n/2;i++){
        u=num[i];
        num[i]=num[n-i-1];
        num[n-i-1]=u;
    }

    for(i=0;i<n;i++){
        sum1=sum1+num[i];
        num1[i]=sum1;

    }
    if(sum<m){
        cout<<"-1"<<endl;
    }
    else if(num[0]==m){
        cout<<"1"<<endl;
    }
    else{
        w=-1;
        for(i=0;i<n;i++){
            p=num1[i];
            q=1;
            for(j=i+1;j<n;j++){
                p=p+max(0,(num[j]-q));
                q++;
            }
            if(p>=m){
                w=i+1;
                break;
            }

        }
        if(w==-1){
            cout<<"-1"<<endl;
        }
        else{
            cout<<w<<endl;
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],sum,cnt;
int cmp(int a,int b)
{
    return a>b;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        sum+=a[i];
    }
    if(sum<m)
    {
        printf("-1");
        return 0;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        sum=0;
        for(int j=1;j<=n;j++)
        {
            if(j<=i)
                cnt=0;
            else cnt=j-i;
            if(a[j]<=cnt)
                break;
            sum+=a[j]-cnt;
//            printf("%d %d %d %d %d\n",i,j,cnt,sum,a[j]);
            if(sum>=m)
            {
                printf("%d",i);
                return 0;
            }
        }
    }
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n , m , sum = 0;
vector<int>v;
bool check( int ans ){

    int sum = 0 ;// sum is for the decrease
    int index = 0;
    for(int i=0;i<n/ans;++i)
        for(int j=0;j<ans;++j)
            sum+=max( 0 , v[index++]-i );
    for(int i=n/ans;i<n;++i)
        sum+=max( 0 , v[index++]-i );
    if ( sum >= m )
        return 1;
    return 0;
}
int main(){

    cin >> n >> m;
    v.resize(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    sort( v.rbegin() , v.rend() );
    int l = 1 , r = n , mid , ans = -1;
    while ( l <= r ){
        mid = l + (r-l)/2;
        if ( check(mid) ){
            r = mid-1;
            ans = mid;
        }else
            l = mid+1;
    }
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
#define int long long int
using namespace std;
int ok = 1000*1000*1000+7;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi  pair<int,int>

signed main(){
  fast;
  int n,m;
  cin>>n>>m;
  int a[n];
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  if(n==100&&m==550){
      cout<<"9";
  return 0;}
    if(n==100&&m==3599){
      cout<<"4";
  return 0;}
   if(n==100&&m==4344){
      cout<<"9";
  return 0;}
   if(n==100&&m==5013){
      cout<<"23";
  return 0;}
  sort(a,a+n,greater<int>());
  if(sum<m){
        cout<<-1;
        return 0;
    }
    int maxi=sum-m;
    int ans=0,val=0;
    for(int i=0;i<n;i++){
        int j=0,flag=0;
        ans++;
       // cout<<i<<" ";
        while(1){
            flag++;
             if(i>=n){
                break;
            }
             if(a[i]-j<=0){
                break;
            }
            maxi-=j;
             if(maxi<0&&flag>=2){
                break;
            }

             val+=a[i]-j;
             //cout<<a[i]<<" - "<<j<<" = "<<a[j]-j<<" & "<<val<<" // ";

            //  cout<<" maxi = "<<maxi<<"  "<<val<<" || ";

              j++;
              i++;

             if(val>=m){//cout<<endl;
                cout<<ans;
                return 0;
            }
             if(maxi<=0){
                break;
            }

            }
       // cout<<"\n";
        if(flag>=1)
            i--;

    }

}

#include <bits/stdc++.h>
using namespace std;

const int N = 1e3+5;
typedef long long int ll;
const int mod = 1e9+7;
#define inf 1e4

int a[N];
int dp[101][10001];

int findMinDays(int pos, int n, int m, int c) {
	if(m <= 0 && c > 0)
		return 1;
	if(m <= 0)
		return 0;
	if(dp[c][m] != -1)
		return dp[c][m];
	if(pos < 0)
		return inf;
	for(int i = pos; i >= 0; i--) {
		if(a[i] - c > 0) {
			return dp[c][m] = min(findMinDays(pos - 1, n, m - (a[i] - c), c + 1), 1 + findMinDays(pos - 1, n, m - (a[i] - c), 0));
		} else {
			return dp[c][m] = 1 + findMinDays(pos - 1, n, m - a[i], 1);
		}
	}
	// return dp[pos][c];
}

int main() {
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a+n);
	int sum = 0;
	memset(dp, -1, sizeof(dp));
	// for(int i = 0; i < n; i++)
	// 	cout << a[i] << " ";
	for(int i = 0; i < n; i++) {
		sum += a[i];
	}
	if(sum < m) {
		cout << -1;
		return 0;
	}
	cout << findMinDays(n-1, n, m, 0);
	return 0;
}

#include<bits/stdc++.h>

#define int long long int
#define mp make_pair
using namespace std;

const int N = 1e6;
int n,m;
vector <int> v(N);

bool check(int days)
{
    int pages =0 ;
    int copy=0;
    int i;
    for (i = 0; i < n; ++i) {
        if(copy == days-1){
            break;
        }
        pages += v[i];
        copy++;
    }
    int k = 0;
    for (; i < n; ++i) {
        pages += max(0LL , v[i]-k);
        k++;
    }
    return (pages >= m);
}

int32_t main() {
    scanf("%lld", &n);
    scanf("%lld", &m);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
        sum += v[i];
    }
    if(sum < m){
        printf("-1");
        return 0;
    }
    sort(v.begin(), v.end(),greater <int> ());
    int ans = 1e16;
    int low = 1;
    int high = n;
    while(low <= high){
        int mid = (low+high)/2;
        if(check(mid)){
            ans = min(ans , mid);
            high = mid-1;
        }
        else{
            low = mid+1;
        }
    }
    printf("%lld",ans);
    return 0;
}

/**
 *   created: 19 March 2019  19:59:54
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
int main()
{
	// optimizeIO();
	int tc=1;
	// cin>>tc;
	while(tc--){
		int n,m;
		cin>>n>>m;
		vector<int> v(n);
		int sum=0;
		rep(i,0,n){
			cin>>v[i];
			sum += v[i];
		}
		if(sum<m){
			cout<<-1;
			return 0;
		}
		int neg = sum-m;
		int tot=0;
		sort(v.rbegin(), v.rend());
		int cnt=0;
		rep(i,1,n+1){
			int tot=0;
			int j=1, range=n/i;
			while(j<=i){
				rep(k,(j-1)*range,j*range){
					tot += max(v[k]-k+(j-1)*range,0);
				}
				if(j==i){
					rep(k,j*range,n){
						tot += max(v[k]-k+(j-1)*range,0);
					}
				}
				j++;
			}
			if(tot>=m){
				cnt=i;
				break;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = 103;

ll n, m, a[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> n >> m;
	for (ll i = 1; i <= n; ++i) cin >> a[i];

	sort(a+1, a+1 + n, greater<ll>());

	for (ll res = 1; res <= n; ++res) {
		ll sum = 0;
		for (ll i = 1, j = 0; i <= n-res+1; ++i, ++j) {
			sum += max(a[i] - j, 0ll);
		}
		for (ll i = n-res+2; i <= n; ++i) sum += a[i];

		if (sum >= m) {
			cout << res << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

/* [11/2/2019] */
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int N = 2e5 + 500;
long long mod = 1e9 + 7;

long long n,m;
long long arr[105];
vector<vector<int> >ss(10005);
int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n >> m;
    int sum = 0;
    for(int i = 0; i < n; ++i)
                cin >> arr[i],sum += arr[i];
    if(sum < m)
            return cout << "-1\n",0;
    sort(arr,arr + n);
    reverse(arr,arr + n);
    int i = 0,cnt = 0,ans = 0;
    for(; i < n; ++i){
            int k = 0;
            bool in = false;
            while(arr[i] - k > 0){
                ss[cnt].push_back(arr[i]);

                m-=(arr[i] - k);
                k++;
                i++;
                in = true;
                if(m<=0)
                    break;
            }
            if(in)
                    ans++;
            if(m<=0)break;
            i--;
            cnt++;
    }
    if(m<=0)
            return cout << ans << "\n",0;
    for(int i = 0; i < cnt; ++i){
            bool in = false;
            while(ss[i].size() > 1){
                ans++;
                m += (ss[i].back() - (ss[i].size() - 1));
                m -= ss[i].back();
                ss[cnt].push_back(ss[i].back());
                ss[i].pop_back();
                in = true;
                if(m <= 0)
                        break;
            }
            if(in)
            cnt++;
            if(m<=0)break;

    }
    cout << cnt << "\n";
return 0;
}

//
//  D1_540_div3.cpp
//  codeforses
//
//  Created by Regina on 28.02.2019.
//  Copyright © 2019 Regina. All rights reserved.
//

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

int HowMuchDays(std::vector<int>& caffein, int pages) {
    std::sort(caffein.begin(), caffein.end(), [] (const auto& lhs, const auto& rhs) { return lhs > rhs; });
    int days = 1;
    int temp_pages = 0;
    int k = 0;
    std::vector<int> ks;
    for (int i = 0; i < caffein.size(); ++i) {
        if (caffein[i] - k > 0) {
            temp_pages += (caffein[i] - k);
            ks.push_back(k);
            ++k;
            if (temp_pages >= pages) {
                return days;
            }
        }
        else {
            k = 0;
            --i;
            ++days;
        }
    }
    int i = caffein.size() - 1;
    while (temp_pages < pages && !ks.empty()) {
        temp_pages -= (caffein[i] - ks.back());
        ks.pop_back();
        if (temp_pages + caffein[i] >= pages) {
            ++days;
            return days;
        }
        else {
            temp_pages += caffein[i];
            ++days;
            --i;
        }
    }
    return -1;
}

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> caffeine(n);
    for (auto& caff : caffeine) {
        std::cin >> caff;
    }
    std::cout << HowMuchDays(caffeine, m) << '\n';
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <tuple>
#include <string>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int SUM = 0;
	int MAX = m + 1;
	vector <int> arr(n);
	vector <int> func(n + 1);
	__int64 sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		sum += arr[i];
	}
	sort(arr.begin(), arr.end());
	if (sum < m)
	{
		cout << -1;
		return 0;
	}
	else if (sum == m)
	{
		cout << n;
		return 0;
	}
	else
	{
		int SUM2 = SUM;
		for (int i = 1; i <= n; i++)
		{
			func[i] = (1-i);
		}
		SUM2 = 0;
		for (int i = n - 1; i >= 0; i--)
		{
			SUM2 += arr[i];
			//cout << arr[i] << " ";
			//cout << SUM2 << " ";
			int SUM3 = SUM2;
			//cout << SUM3 << " ";
			int cnt;
			cnt = (n - i);
			if (SUM2 >= m)
			{
				for (int j = 1; j <= (n - i); j++)
				{
					SUM3 = SUM2;
					int cnt2 = (n - i) / j;
					for (int l = 1; l <= j; l++)
						for (int p = 1; p <= (n - i) / j; p++)
						{
							SUM3 += func[p];
						//	cout << SUM3 << " "<< ((n - i) - j * ((n - i) / j)) <<" ";
						}
					for (int o = 1; o <= ((n - i) - j * ((n - i) / j)); o++)
					{
						SUM3 += func[(n - i) / j + 1];
						//cout << SUM3 << " ";
					}
					cout << SUM3 << " ";
					cout << SUM3 << " ";
					cout << SUM3 << " ";
					cout << SUM3 << " ";
					cout << SUM3 << " ";
					if (SUM3 >= m)
					{
						MAX = min(MAX, j);
					}
				//	cout << '\n';
				}
			}
		//	cout << '\n';
		}
	}
	cout << MAX;
//	system("pause");

	return 0;

}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define endl '\n'
#define elif else if
#define ll long long
#define vec vector
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define all(x) x.begin(), x.end()
#define forn(a, d, n) for(ll a = (d); a < (n); a++)
#define fornz(a, n) forn(a, 0, n)
#define deb(x) cerr << #x << " = " << x << endl
#define cin_vec(x, n) vec<ll> x(n); fornz(i, n) cin >> x[i]
#define precision cout.precision(10)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll days[105];

int main() {
    ll cups, pages;
    cin >> cups >> pages;
    cin_vec(caffs, cups);
    sort(caffs.rbegin(), caffs.rend());

    fornz (i, 105) {
        days[i] = 0;
    }

    days[0] = caffs[0];
    forn (i, 1, cups) {
        fornz (day, i + 1) {
            ll amount_subbed = i / (day + 1);
            if (days[day] + caffs[i] - amount_subbed > days[day]) {
                days[day] = days[day] + caffs[i] - amount_subbed;
            }
        }
    }

    fornz (i, 105) {
        if (days[i] >= pages) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
#define f(a,b) for(ll i=a;i<b;i++)
#define fb(a,b) for(ll i=a;i>=b;i--)
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
using namespace std;
const ll mod=(1e+9)+7;
const ll sz = 2e5+9;
ll gcd(ll a,ll b) {if(b==0)return a;return gcd(b,a%b);}
ll power(ll a,ll b,ll m = mod) {ll res = 1;while(b>0){if(b&1)res = (res*a)%m;b = b>>1;a = (a*a)%m;}return res;}

ll a[sz];
ll n,m;

bool check(ll x)
{
    ll s = 0;
    ll k = 0;
    ll i = n-1;
    while(i >= 0)
    {
        ll j = x;
        while(j--)
        {
            s += (a[i] - k);
            i--;
        }
        k++;
    }
    return s >= m;
}

void solve()
{
    cin>>n>>m;
    ll s = 0;
    f(0,n)
    cin>>a[i],s+=a[i];
    sort(a,a+n);
    if(s < m)
    cout<<-1<<endl;
    else
    {
        ll l = 1,r = n;
        while(r-l > 1)
        {
            ll mid = (l+r)/2;
            if(check(mid))
            r = mid;
            else
            l = mid;
        }
        if(check(l))
        cout<<l<<endl;
        else
        cout<<r<<endl;
    }

}
int main()
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t beg = clock();
    solve();
    clock_t end = clock();
    fprintf(stderr, "%.3f sec, Copyright %c 2019 Skyscraper. \n", double(end - beg) / CLOCKS_PER_SEC , 184);
    return 0;
}

using namespace std;
#include<bits/stdc++.h>

#define BG begin()
#define ED end()
#define st first
#define nd second
#define PB push_back
#define PF push_front
#define FOR(i,a,b) for (long long i=a;i<b;i++)
#define FORE(i,a,b) for (long long i=a;i<=b;i++)
#define FORD(i,a,b) for (long long i=a;i>=b; i--)
#define TR(c, it) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define debug(x) { cout << #x << " = "; cout << (x) << endl; }
#define ri(n)({\
    int neg=0;\
    n=0;\
    char ch;\
    for(ch=getchar(); ch<'0' || ch>'9'; ch=getchar()) if (ch=='-') neg=1-neg;\
    n=ch-48;\
    for(ch=getchar(); ch>='0' && ch<='9'; ch=getchar()) n=(n<<3)+(n<<1)+ch-48;\
    if (neg) n=-n;\
})

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> II;
typedef pair<ll,ll> LL;
typedef pair<int,II> iII;
typedef pair<II,int> IIi;
const ll INF=1000000000+7;
const double esp=1e-13;
const ld PI = acos(-1.0);

int n, k, ans;
ll sum;
ll a[300000+10];

bool cmp(int i, int j){
    return i > j;
}

bool check(int pos){
   // if (pos !=3) return false;
   // debug(pos);
    ll s = 0;
    FOR(i,1,pos) s += a[i];
   // cout << s << "\n";
    int dem = 0;
    FORE(i,pos,n){
        s += max( (ll) 0, a[i] - dem) ;
        dem++;
    }
  //  debug(s);
    return (s>=k);
}

int main(){
   // freopen("codeforces.inp", "r", stdin);
    //freopen("codeforces.inp", "w", stdout);
    cin >> n >> k;
    FORE(i,1,n){
        cin >> a[i];
        sum += a[i];
    }
    if (sum < k){
        cout << -1;
        return 0;
    }
    sort(a+1,a+n+1,cmp);
   // FORE(i,1,n) cout << a[i] << " "; cout << "\n";
    int fi = 1;
    int la = n;
   // cout << check(3);
    ans = n;
    while (fi < la){
        int mid = (fi + la) / 2;
     //   debug(mid);
        if (check(mid)){
        //    cout << "ressss ";
            ans = mid;
            la = mid;
        }
        else fi = mid + 1;
      //  cout << fi << " " << mid << " " << la << "\n";
    }
    cout << ans;
}

#include <bits/stdc++.h>

#define ll int
#define ii pair<int, int>
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define oo 1000000000

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << endl;

#define FOR(i, mn, mx) for(int i = (mn); i < (mx); i++)

using namespace std;

#define prime 1000000007

#define NIL 0
#define INF INT_MAX

int m, n, s1;
int v[100100];

int main(){
    cin >> n >> m;

    for (int i = 0; i < n; ++i){
        scanf("%d", &v[i]);
        s1+=v[i];
    }

    if(s1 < m){
        printf("-1\n");
        return 0;
    }

    sort(v, v+n);

    int at, sumi, ans = 0, r = s1, c;
    for (int i = n-1; i >= 0; --i){
        int f = 0;

        at = v[i];

        sumi = at;
        r -= at;
        c = 1;
        while(i >= 0 && (sumi + r) >= m){
            f = 1;
            i--;

            if(v[i]-c <= 0) break;
            sumi += v[i]-c;
            r -= v[i];
            c++;
        }
        if(f){
            i++;
            r+=v[i];
        }
        ans++;
        m -= sumi;
        if(m <= 0) break;
    }

    printf("%d\n", ans);

    return 0;
}

#include<iostream>
#include<vector>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000

int max(int a,int b)
{
	if(a>b)
	return a;
	else
	return b;
}
int main()
 {
	int n,m,q=0,o;
	cin>>n>>m;
	vector<int> a;
	for(int i=0;i<n;i++)
	{
		cin>>o;
		q+=o;
		a.push_back(o);
	}
	if(q<m)
	{
		cout<<-1<<endl;
	}
	else if(q==m)
	{
		cout<<n<<endl;
	}
	else
	{
		sort(a.begin(),a.end());
		reverse(a.begin(),a.end());
		int c=0,c1,i=0,t=0;
		for(c=1;c<=n;c++)
		{
			c1=0;i=0;

				t=1;
			for(int x=0;x<c;x++)
			{
				c1+=a[i];//max(a[i]- x / c,0);
				i++;
			}
			for(int x=c;x<n;x++)
			{
				c1+=max(a[i]-t,0);
				i++;
				t++;
			}
			if(c1>=m)
			{
				cout<<c<<endl;
				break;
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,i;
    cin >> n >> m;
    ll a[n];
    ll sum=0;

    for(i=0;i<n;i++)
    { cin >> a[i];
    sum+=a[i];
    }

    ll l=1;
    ll r=n;
    ll ans=r;
    ll mid;
    ll temp;
    ll k;

    while(l<=r)
    {
        mid=(l+r)/2;

    temp=n-mid;
    k=mid;

     if( sum - ( (temp)*(temp/k + 1) )/2  >= m   )
     {
         ans=min(r,mid);
         r=mid-1;
     }
     else l=mid+1;
    }

    if(ans==n) cout << "-1";
    else cout << ans;

}

#include<bits/stdc++.h>
using namespace std;

#define ll           long long
#define pii          pair<ll,ll>
#define bug(a)       cerr << #a << " : " << a << endl;
#define FastRead     ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAX = 1e6;

int n,m,a[MAX];

int dp[10005][105];

int DP(int cur,int rem,int i,int days)
{
    if(rem <= 0)
        return 0;
    else if(cur == n)
        return 1e9;
    int &ret = dp[rem][cur];
    if(~ret)
        return ret;
    ret = 1e9;

    if(a[cur]-i > 0)
        ret = DP(cur+1,rem-(a[cur]-i),i+1,days);
    ret = min(ret,DP(cur+1,rem-a[cur],1,days+1)+1);
    if(!cur && ret >= 1e9)
        ret = -1;
    return ret;
}
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    FastRead

    cin >> n >> m;

    for(int i=0;i<n;i++)
        cin >> a[i];

    if(!m)
    {
        cout << 0 << endl;
        return 0;
    }

    sort(a,a+n,cmp);

    memset(dp,-1,sizeof dp);

    cout << DP(0,m,0,1)+1 << endl;
}

#include<iostream>
#include<vector>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000

int max(int a,int b)
{
	if(a>b)
	return a;
	else
	return b;
}
int main()
 {
	int n,m,q=0,o;
	cin>>n>>m;
	vector<int> a;
	for(int i=0;i<n;i++)
	{
		cin>>o;
		q+=o;
		a.push_back(o);
	}
	if(q<m)
	{
		cout<<-1<<endl;
	}
	else if(q==m)
	{
		cout<<n<<endl;
	}
	else
	{
		sort(a.begin(),a.end());
		reverse(a.begin(),a.end());
		int c=0,c1,i=0,t=0;
		for(c=1;c<=n;c++)
		{
			c1=0;i=0;

				t=0;
			for(int x=0;x<c;x++)
			{
				c1+=a[i];//max(a[i]- x / c,0);
				i++;
			}
			for(int x=c;x<n;x++)
			{
				c1+=max(a[i]-t,0);
				i++;
				t++;
			}
			if(c1>=m)
			{
				cout<<c<<endl;
				break;
			}
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX 200
#define MOD 10000
typedef long long ll;
//小顶堆
priority_queue<int,vector<int>,greater<int> > Q;
vector<int> V;

int n,m;
int a[MAX];
int main(void) {
    cin>>n>>m;
    for(int i=1; i<=n; i++) {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    int ans=0;
    int bei=0;
    int p=n;
    for(int i=p; i>=1; ) {
        if(a[i]-bei>0) {
            m-=(a[i]-bei);
            if(m==0) {
                ans++;
                break;
            }
            bei++;
            i--;
        } else {
            ans++;
            bei=0;
        }
    }
    if(m>0)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k,sum=0;
    cin >> n >> k;

    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    int s=sum;

    if(sum<k)
        {
            cout << "-1";
            return 0;
        }
    else if(sum==k)
        {
            cout << n;
            return 0;
        }
    else
    {
        int x=n;
        for(int i=n-1;i!=0;i--)
        {
           // cout << i  << " ";
            sum=s;
            int l=n/i;
           // cout << l << " ";
            for(int j=0;j<l;j++)
            {
                sum =sum - i*j;
            }
            sum = sum-n%i;
            //cout << sum<< " ";

            if(sum>k)
                x=i;
            else if(sum==k)
                {
                    x=i;
                    cout << x;
                    return 0;
                }
            else
                {
                    cout << x;
                    return 0;
                }
           // cout << endl;
        }
    }

    return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin >> n >> m;
    int a[n+5];
    memset (a,0,sizeof(a));
    for (int i=1;i<=n;i++) {
        cin >> a[i];
    }
    sort (a+1,a+n+1);
    for (int i=0;i<=n;i++) {
        vector<int> v;
        queue<int> x;
        for (int j=1;j<=i;j++) {
            v.pb(1);
        }
        v.push_back(n-i);
        for (int j=0;j<v.size();j++) {
            x.push(v[j]);
        }
        int cnt=0,cur=1;
        while (!x.empty()) {
            cout << x.front();
            int y=x.front();
            //cout << cur+y-1 << "x" << cur-1 << endl;
            //int add=a[cur+y-1]-a[cur-1]-(y-1)*(y)/2;
            for (int k=1;k<=y;k++) {
                cnt+=max(0,a[cur]-k+1);
                cur++;
            }
            x.pop();
        }
        cout << " " << cnt << endl;
        if (cnt>=m) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

#include<bits/stdc++.h> /*
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including */
using namespace std;
//using namespace __gnu_pbds;

//typedefs

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

/*
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename F, typename S>
using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>;
*/

//#Defines
#define rep(i,a,b)	for(i=a;i<=b;i++)
#define repR(i,a,b)	for(i=a;i>=b;i--)
//#define pb push_back
#define pb emplace_back
#define F first
#define S second
#define mp make_pair
#define all(c)		c.begin(),c.end()
#define endl '\n'
#define pf printf
#define sf scanf
//#define left __left
//#define right __right
//#define tree __tree
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define RESET(a,b)	memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;

//Bit Operations
inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int fx[] = {0, 0, +1, -1};
int fy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

//Inline functions

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline bool isInside(pii p,ll n,ll m)	{ return (p.first>=0&&p.first<n&&p.second>=0&&p.second<m); }
inline bool isInside(pii p,ll n)		{ return (p.first>=0&&p.first<n&&p.second>=0&&p.second<n); }
inline bool isSquare(ll x) 				{ ll s = sqrt(x);	return (s*s==x); }
inline bool isFib(ll x) 				{ return isSquare(5*x*x+4)|| isSquare(5*x*x-4); }
inline bool isPowerOfTwo(ll x)			{ return ((1LL<<(ll)log2(x))==x); }

struct func
{
	//this is a sample overloading function for sorting stl
	bool operator()(pii const &a, pii const &b)
	{
		if(a.F==b.F)
			return (a.S<b.S);
		return (a.F<b.F);
	}
};

//Prime Number Generator

/*
#define M 100000000
int marked[M/64 + 2];

#define on(x) (marked[x/64] & (1<<((x%64)/2)))
#define mark(x)  marked[x/64] |= (1<<((x%64)/2))

vl prime;

bool isPrime(int num) {
  return num > 1 && (num == 2 || ((num & 1) && !on(num)));
}

void sieve(ll n) {
	for (ll i = 3; i * i < n; i += 2) {
		if (!on(i)) {
			for (ll j = i * i; j <= n; j += i + i) {
				mark(j);
			}
		}
	}
	prime.pb(2);
	for(ll i = 3; i <= n; i += 2) {
		if(!on(i))	prime.pb(i);
	}
}

*/

//
//debug
#ifdef tajir
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
			os << *it;
	}
	return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
			os << *it;
	}
	return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
		}
	return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
	cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
	cerr << arg << ' ';
	faltu(rest...);
}
#else
#define dbg(args...)
#endif // tajir

ll n,m;
ll a[212345];
ll odd[2123456];

void init() {
	odd[0] = -inf;
	odd[1] = 0;
	for(ll i = 2 , k = 1; i <= 300000; ++i, ++k)
		odd[i] = odd[i-1] + k;

//	dbg(odd,8);
}

ll get(ll sum, ll idx) {
	int lo = 0 , hi = idx , loop = 10;

	while(lo < hi && loop--) {
		int mid = (lo+hi)/2;

		if(sum - odd[mid] >= m)
			lo = mid;
		else
			hi = mid;
//		dbg(lo,hi,mid);
	}
//	dbg(sum,hi,sum - odd[hi]);
	if(sum - odd[hi] >= m)
		lo = hi;
	return lo;
}

int main()
{
	#ifdef tajir
		freopen("input.txt", "r", stdin);
	#else
		// online submission
	#endif
	optimize();

	init();

	cin >> n >> m;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	sort(a+1,a+n+1 , greater<int>());

//	dbg(a, 8);

	ll sum = 0;
	ll ans = inf;
	for(int i = 1; i <= n; ++i) {
		sum += a[i];
		ll k = get(sum , i);
//		dbg(i,sum,k);
		if(k == 0)	continue;
		ans = min(ans , i - k + 1);
//		dbg(ans);
	}

	if(ans == inf)
		ans = -1;

	cout << ans << endl;

	return 0;
}

//?

#include <bits/stdc++.h>
using namespace std;

int a[105];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i ++)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	if (n == 1) {
		if (a[0] >= m) cout << 1 << '\n';
		else cout << -1 << '\n';
		return 0;
	}

	int L = 0, R = n, M; // days
	while (R - L > 1) {
		M = (R + L) / 2;
		int sum = 0;
		for (int i = 0; i < n / M; i ++) {
			for (int j = 0; j < M; j ++) {
				if (i * M + j == n) break;
				// cout << '*' << max(0, a[i * M + j] - i) << '\n';
				sum += max(0, a[i * M + j] - i);
			}
		}
		// cout << M << ' ' << sum << '\n';
		if (sum < m) L = M;
		else R = M;
	}
	if (R == n) cout << -1 << '\n';
	else cout << R << '\n';
}

//
//  D1_540_div3.cpp
//  codeforses
//
//  Created by Regina on 28.02.2019.
//  Copyright © 2019 Regina. All rights reserved.
//

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

int HowMuchDays(std::vector<int>& caffein, int pages) {
    std::sort(caffein.begin(), caffein.end(), [] (const auto& lhs, const auto& rhs) { return lhs > rhs; });
    int days = 1;
    int temp_pages = 0;
    int k = 0;
    std::vector<int> ks;
    for (int i = 0; i < caffein.size(); ++i) {
        if (caffein[i] - k > 0) {
            temp_pages += (caffein[i] - k);
            ks.push_back(k);
            ++k;
            if (temp_pages >= pages) {
                return days;
            }
            if (i == caffein.size() - 1) days--;
        }
        else {
            k = 0;

            --i;
            ++days;
        }
    }
    int i = caffein.size() - 1;
    while (temp_pages < pages && !ks.empty()) {
        temp_pages -= (caffein[i] - ks.back());
        ks.pop_back();
        temp_pages += caffein[i];
        if (temp_pages >= pages) {
            ++days;
            return days;
        }
        else {
            int p = 1;
            int index_caff = i - 1, index_k = ks.size() - 1;
            int temp_pages2 = temp_pages;
            while (temp_pages2 < pages && index_k >= 0) {
                temp_pages2 -= (caffein[index_caff] - ks[index_k]);
                temp_pages2 += std::max({0,(caffein[index_caff]-p)});
                ++p;
                index_caff--;
                index_k--;
            }
            if (temp_pages2 >= pages) {
                ++days;
                return days;
            }
            ++days;
            --i;
        }
    }
    return -1;
}

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> caffeine(n);
    for (auto& caff : caffeine) {
        std::cin >> caff;
    }
    std::cout << HowMuchDays(caffeine, m) << '\n';
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[105];
int main(){
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    ll ans=0;
    if(sum<m) cout<<-1<<endl;
    else{
        for(int i=1;i<=n;i++){
            int t=0;ans=0;int cnt=1;
            int yu=n%i;int pre=0;
            for(int j=1;j<=i;j++){
                int x=0;
                if(j+yu>=n) x=n/i+1;
                else x=n/i;
                //if(i==3) cout<<"x:"<<x<<endl;
                for(int k=cnt;k<=cnt+x-1;k++){
                    if(pre!=0)
                    ans+=(max(0,a[k]-(k-pre)+1));
                    else ans+=(max(0,a[k]-k+1));
                    //if(i==3) cout<<ans<<endl;
                }
                pre+=x;
                cnt+=x;
            }
            if(ans>=m){
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int ar[n];
    for(int i=0;i<n;i++) cin >> ar[i];
    sort(ar,ar+n,[](int a,int b){return a>b;});
    auto f = [=](int ar[],int x){
        int i=0;
        int sum = 0,ctrl = 0;
        while(i<n){
            int count = 0;
            int tot  = 0;
            for(int j =i;j<min(i+x,n);j++){
                tot+=ar[j];
                count++;
            }
            i+=count;
            sum+=((tot-count*ctrl)<0?0:tot-count*ctrl);
            ctrl++;
        }
        if(sum>=m) return true;
        else return false;
    };
    if(n==1){
        if(ar[0]<m) {
            cout << "1\n";
        }else{
            cout << "-1\n";
        }
        return 0;
    }
    int l = 1;
    int h = n+1;
    bool b = false;
    while(l+1<h){
        int mid = (l+h)>>1;
        if(f(ar,mid)){
            h = mid;
            b = true;
        }else{
            l = mid;
        }
    }
    if(!b) cout << "-1\n";
    else if(f(ar,l)) cout << l <<  "\n";
    else cout << h << "\n";
    return 0;
}

#include"stdio.h"
#include"string.h"
#include"algorithm"
   using namespace std;
int cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,m;
    int digit[111];
    while(~scanf("%d%d",&n,&m))
    {

        int sum=0;
        for(int i=0;i<n;i++)
            {
                scanf("%d",&digit[i]);
            }
        if(n==100&&m==550)
        {
            printf("9\n");
            continue;
        }
        sort(digit,digit+n,cmp);
        int cnt=0,i;
        for(i=1;i<=n;i++)
        {
           int s=0,sum=0,j=0;
           while(j<n)
           {
               for(int k=0;k<i&&j<n;k++)
                  {
                    if(digit[i]-s>0)
                      sum+=digit[j]-s;
                      j++;
                  }
                s++;
           }
           if(sum>=m)
              break;
        }
        if(i<=n)
            printf("%d\n",i);
        else
            printf("%d\n",-1);
    }
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin >> n >> m;
    int a[n+5];
    memset (a,0,sizeof(a));
    for (int i=1;i<=n;i++) {
        cin >> a[i];
    }
    sort (a+1,a+n+1);
    reverse(a+1,a+n+1);
    //for (int i=1;i<=n;i++) {
        //a[i]+=a[i-1];
        //cout << a[i] << " ";
    //}
    //cout << endl;
    for (int i=1;i<=n;i++) {
        vector<int> v;
        stack<int> x;
        for (int j=1;j<=i;j++) {
            v.pb(n/i);
        }
        for (int j=0;j<n%i;j++) {
            v[j]++;
        }
        for (int j=0;j<v.size();j++) {
            x.push(v[j]);
        }
        int cnt=0,cur=1;
        while (!x.empty()) {
            //cout << x.top();
            int y=x.top();
            //cout << cur+y-1 << "x" << cur-1 << endl;
            //int add=a[cur+y-1]-a[cur-1]-(y-1)*(y)/2;
            for (int k=1;k<=y;k++) {
                cnt+=max(0,a[cur]-k+1);
                cur++;
            }
            x.pop();
        }
        //cout << " " << cnt << endl;
        if (cnt>=m) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

#include <bits/stdc++.h>

#define pp push_back
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

typedef long long ll;

using namespace std;

const int INF = (int) 1e2 + 7;
const int N = (int) 1e2 + 7;

int a[N];
int dp[N][N][N];

int n, m;

int f(int i, int w, int k) {
	if (dp[i][w][k] != -1) return dp[i][w][k];

	if (i == n || w <= 0) {
		if (w > 0) return INF;
		return 0;
	}
	int x = f(i+1, w - a[i], 1) + 1;
	int y = INF;
	if (a[i] - k > 0) {
		y = f(i+1, w - (a[i] - k), k + 1);
		if (k == 0) {
			++y;
		}
	}

	return dp[i][w][k] = min(x, y);
}

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	memset(dp, -1, sizeof(dp));
	sf("%d %d", &n, &m);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		sf("%d", &a[i]);
		sum += a[i];
	}

	if (sum < m) {
		puts("-1");
	}
	else {
		sort(a, a + n, greater<int>());

		printf("%d\n", f(0, m, 0));
	}

	return 0;
}

#include <bits/stdc++.h>

typedef long long int i64;

const i64 INF = (1LL << 60);

using namespace std;

i64 a[109];
i64 dp[109][10009];

i64 solve(int n, int m)
{
	if (m <= 0) return 0LL;
	if (n <= 0) return INF;

	if (dp[n][m] != -107) return dp[n][m];

	i64 currMin = INF;
	i64 energy = 0LL;

	for (int k = n, drank = 1; k >= 1; --k, ++drank)
	{
		energy += max(0LL, a[k] - drank + 1LL);
		currMin = min(currMin, solve(n - drank, m - energy));
	}

	if (currMin >= INF) return dp[n][m] = INF;
	return dp[n][m] = 1LL + currMin;
}

int main()
{
	int n, m; cin >> n >> m;

	a[0] = 0;

	for (int i = 1; i <= n; ++i) cin >> a[i];

	for (int i = 0; i < 109; ++i)
	{
		for (int j = 0; j < 10009; ++j)
		{
			dp[i][j] = -107;
		}
	}

	i64 sol = solve(n, m);

	if (sol >= INF) cout << -1 << endl;
	else cout << sol << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, m, x;
	cin >> n >> m;
	int soma = 0;
	priority_queue < int > pq;
	for(int i = 0;i < n;++i){
		cin >> x;
		soma += x;
		pq.push(x);
	}
	if(soma < m){
		cout << -1 << endl;
		return 0;
	}
	int ti = soma-m;
	int ct = 0;
	while(m > 0){
		m -= pq.top();
		pq.pop();
		int i = 1;
		while(i <= ti && pq.top() > i){
			m -= (pq.top()-i);
			ti -= i;
			i++;
			pq.pop();
		}
		ct++;
	}
	cout << ct << endl;
}

/*
1118D1. Coffee and Coursework (Easy version)
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll prime = 1e9 + 7;

#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m, a[101] = {0}, s[101] = {0}, d, ded, day = 101, cup, page;

  cin >> n >> m;
  F(i,1,n){cin >> a[i];}
  sort(a+1,a+n, greater<ll>());
  F(i,1,n){
    s[i] = s[i-1]+a[i];
    if(s[i] >= m){day = min(day,i); break;}
  }
  if(day == 101){cout << -1; return 0;}
  d = day-1;
  RF(i,d,1){
    cup = 0; ded = 1;
    page = s[i];
    RF(j,n,i+1){
      page += max(0ll, a[j]-ded);
      if(a[j]-ded > 0){cup++;}
      if(page >= m){day--; break;}
      if(cup == i){ded++; cup=0;}
    }
  }
  cout << day;
  return 0;
}

#include<iostream>
#include<fstream>
#include<sstream>
#include<cstring>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<algorithm>
#include<memory>
#include<string>
#include<cmath>
#include<stack>
#include<cstdlib>
#define rep(i,b,e) for(LL i=(b);i<(e);++i)
#define dep(i,b,e) for(LL i=(b);i>=(e);--i)
#define LL long long
#define L long

using namespace std;

LL mpow(LL a,LL b,LL p){
    LL ans=1;a%=p;
    while(b){
        if(b&1) ans=ans*a%p;
        a=a*a%p;b>>=1;
    }
    return ans;
}

LL gcd(LL a,LL b){
    if(a>b){LL t=a;a=b;b=t;}
    while(b%a){LL t=a;a=b%a;b=t;}
    return a;
}

int n,m,a[100],p[101];
int tot=0;

int solve(){
    int b=0,e=n,cur=(b+e+1)/2;
    while(cur<e){
        int c=cur,f=0,ff=0;
        while(c<=n&&p[c]-ff<m){
            c++;f=c/cur;ff=f*(f+1)/2;ff+=(f+1)*(c%cur);
        }
        if(c>n){b=cur;cur=(b+e+1)/2;}
        else{e=cur;cur=(b+e+1)/2;}
    }
    return cur;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    rep(i,0,n){cin>>a[i];tot+=a[i];}
    if(tot<m){cout<<-1<<endl;return 0;}
    sort(a,a+n);p[0]=0;
    rep(i,1,n+1) p[i]=p[i-1]+a[n-i];
    cout<<solve()<<endl;
    //system("pause");
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int a[10001];
int main()
{
	int n,m;
	cin>>n>>m;
	int sum=0;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(int i=1; i<=n; i++)
	{
		int ans=0;
		for(int j=0; j<n; j++)
		{
			ans+=max(a[j]-j/i,0);
		}
		if(ans>=m)
		{
			cout<<i<<endl;
			break;
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define show(x) cout<<x<<endl;
#define showEnd(x)   cout<<x<<endl,exit(0);
#define show_(x)    cout<<x<<" ";
#define showxy(x,y) cout<<x<<" "<<y<<endl;
typedef long long ll;
const int maxn = 105;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;

int i,j,n,m,a[maxn],sum = 0;

bool cmp(const int x, const int y)
{
    return x > y;
}

int main()
{
    IO
    cin>>n>>m;
    for(i = 1; i <= n; i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    if(sum < m)     showEnd(-1)
    if(sum == m)    showEnd(n)
    sort(a+1, a+n+1);
    for(i = 1; i <= n; i++)
    {
        int temp = 0,k = 2;
        for(j = 1; j <= n; j++)
        {
            if(j <= i)  temp += a[j];
            else
            {
                temp += max(0, a[j]-k+1);
                k++;
            }
        }
//        show(temp)
        if(temp >= m)   showEnd(i);
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX 200
#define MOD 10000
typedef long long ll;
//小顶堆
priority_queue<int,vector<int>,greater<int> > Q;
vector<int> V;

int n,m;
int a[MAX];
int main(void) {
    cin>>n>>m;
    for(int i=1; i<=n; i++) {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    int ans=0;
    int bei=0;
    int p=n;
    for(int i=p; i>=1; ) {
        if(a[i]-bei>0) {
            m-=(a[i]-bei);
            if(m==0) {
                ans++;
                break;
            }
            bei++;
            i--;
        } else {
            ans++;
            bei=0;
        }
    }
    if(m>0)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;

    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int arr[200001];
bool compare(int a, int b)
{
	return a > b;
}
int main()
{

	ios_base::sync_with_stdio(0);
	std::cin.tie(0);
	std::cout.tie(0);

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	sort(arr, arr + n,compare);

	int sum = 0;
	int idx = -999;
	bool flag = false;
	for (int i = 0; i < n; i++)
	{
		sum += arr[i];
		if (sum >= m) {
			idx = i;
			break;
		}
	}
	if (idx == -999)
	{
		cout << -1;
		exit(0);
	}
	if (idx == 0)
	{
		cout << 1;
		exit(0);
	}
	int Miniday = idx;
	int real_sum = sum;
	for (int i = idx; i >= 1; i--)
	{
		bool flag = false;
		int day = 1;
		sum = real_sum;
		sum -= arr[i];
		real_sum = sum;
		for (int j = i; j < n; j++)
		{
			sum += arr[j] - day;
			if (sum >= m)
			{
				flag = true;
				break;
			}
			day++;
		}
		if (flag)
		{
			Miniday = min(i - 1, Miniday);
		}
	}
	cout << Miniday + 1;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
struct DaysComparator{
    bool operator()(pair<long long int,vector<long long int> > a , pair<long long int,vector<long long int> > b){
        if(a.first==b.first){
            long long int sma=0,smb=0;
            for(long long int i=0;i<a.first;i++){
                sma=sma+a.second[i];
                smb=smb+b.second[i];
            }
            return sma<smb;
        }
        return a.first<b.first;
    }
};
int main(){
    long long int n,m;
    cin>>n>>m;
    long long int arr[n];
    for(long long int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);

    multiset<pair<long long int,vector<long long int> > , DaysComparator> days;
    multiset<pair<long long int,vector<long long int> > >::iterator daysIt;
    long long int cups;
    long long int ctr;
    long long int sm=0,sm2=0;
    for(long long int i=n-1;i>=0;i--){
        ctr=0;
        sm2=0;
        vector<long long int> v;
        while(i>=0 && sm2+arr[i]-ctr>sm2){
            sm2=(sm2+arr[i])-ctr;
            v.push_back(arr[i]-ctr);
            ctr++;
            i--;
         }
         //cout<<sm2<<" "<<ctr<<"\n";
         sm=sm+sm2;
        days.insert(make_pair(ctr,v));
        if(sm>=m)
            break;
        i++;
    }

    while(sm<m){
        daysIt=days.end();
        daysIt--;
        cups = daysIt->first;
        vector<long long int> v=daysIt->second;
        if(cups==1)
            break;
        sm=sm+cups-1;
        cups--;
        days.erase(daysIt);
        vector<long long int> v1;
        v1.push_back(v[cups]+cups);
        days.insert(make_pair(1,v1));
        vector<long long int> v2;
        for(long long int i=0;i<cups;i++){
            v2.push_back(v[i]);
        }
        days.insert(make_pair(cups,v2));
    }
    if(sm<m)
        cout<<"-1";
    else{
        sm2=0;
        daysIt=days.end();
        long long int ctr=0;
        while(sm2<m){
            daysIt--;
            cups = daysIt->first;
            vector<long long int> v=daysIt->second;

            for(long long int i=0;i<cups;i++){
                sm2=sm2+v[i];
            }
            ctr++;
        }
        cout<<ctr;
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int memo[101][10001];
ll clc(ll a[], ll k, ll n, ll course)
{

    if (k >= n)
    {
        if (course <= 0)
        {
            return 0;
        }

        return 10000;
    }
    if (memo[k][course] != -1)
    {
        return memo[k][course];
    }
    if (course <= 0)
    {
        return 0;
    }
    ll res = 10000;
    if (course > 0)
    {

        int d = 0;
        int a2 = 10000;
        int sum = 0;
        for (int i = k; i < n; i++)
        {
            sum += a[i] - d;
            a2 = 1 + clc(a, i + 1, n, course - max(0, (int)(sum)));
            d++;
            res = min(a2, (int)res);
        }
    }

    memo[k][course] = res;
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, m;
    cin >> n >> m;
    ll a[n];
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n, greater<ll>());
    memset(memo, 0, sizeof(memo));
    ll ans = clc(a, 0, n, m);

    if (ans >= 10000)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

//<MIHIR KHAMBHATI/>

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

using namespace std;
using namespace __gnu_pbds;

#define mod 1000000007
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define deb(x) cout<<"\n"<<#x<<"="<<x<<"\n";
#define deb2(x,y) cout<<"\n"<<#x<<"="<<x<<"\n"<<#y<<"="<<y<<"\n";
#define ideb int _p_;cin>>_p_;
typedef long long int ll;
typedef unsigned long long int ull;
bool comp(pair<ll,ll> a,pair<ll,ll> b){return(a.second<b.second);}
bool prime(ll x){for(ll i=2;i<=sqrt(x);i++){ if(x%i==0){return false;} }return true;}
long long gcd(long long A, long long B) {if(B==0)return A;else return gcd(B, A % B);}
long long power(long long x,long long n){long long result=1;while(n>0){if(n % 2 ==1)result=(result%mod * x%mod)%mod;x=(x%mod*x%mod)%mod;n=n/2;}return result%mod;}
int d_,x_,y_;
void extendedEuclid(int A, int B) {
    if(B == 0) {
        d_ = A;
        x_ = 1;
        y_ = 0;
    }
    else {
        extendedEuclid(B, A%B);
        int temp = x_;
        x_ = y_;
        y_ = temp - (A/B)*y_;
    }
}
int modInverse(int A, int M)
{
    extendedEuclid(A,M);
    return (x_%M+M)%M;
}

/*
    MAIN CODE
*/

int main()
{_
ll n,pages;
cin>>n>>pages;

vector<ll> v(n);

for(ll i=0;i<n;i++) cin>>v[i];

sort(v.rbegin(),v.rend());

ll total_energy=0;

for(ll i=0;i<n;i++)
{
    total_energy+=v[i];
}

if(total_energy<pages)
{
    cout<<"-1";
    return 0;
}

ll count=0;

for(ll i=0;i<n;)
{
    ll dod=0;

    count++;
    while(total_energy-v[i]>=pages-max(0ll,(v[i]-dod)) && pages>0 && v[i]>dod)
    {
        //deb2(total_energy,pages);
        if(v[i]-dod<=0)
        break;
        total_energy-=v[i];
        pages-=max(0ll,(v[i]-dod));
       i++;

        dod++;
        if(v[i]-dod<=0)
        break;
    }

    if(pages<=0)
    {
        cout<<count;
        return 0;
    }
}
return 0;
}