//
// Created by rvg77 on 01.03.19.
//

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 2 * (int)1e5 + 13;

int n, m;

int a[MAXN];

bool can(int days) {
  long long done = 0;
  for (int i = 0; i < n; ++i) {
    done += max((long long)0, (long long)(a[i] - i / days));
  }

  return done >= (long long)m;
}

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

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

  cin >> n >> m;

  long long sum = 0;

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

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

  sort(a, a + n, cmp);

  int l = 1, r = n;

  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }

  if(can(l))
    cout << l;
  else
    cout << r;
  return 0;
}


//
// Created by rvg77 on 01.03.19.
//

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 2 * (int)1e5 + 13;

int n, m;

int a[MAXN];

bool can(int days) {
  long long done = 0;
  for (int i = 0; i < n; ++i) {
    done += max(0, a[i] - i / days);
  }

  return done >= m;
}

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

int main() {

  cin >> n >> m;

  long long 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, cmp);

  int l = 0, r = n;

  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }

  cout << r;
  return 0;
}


//
// Created by rvg77 on 01.03.19.
//

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 2 * (int)1e5 + 13;

int n, m;

int a[MAXN];

bool can(int days) {
  long long done = 0;
  for (int i = 0; i < n; ++i) {
    done += max((long long)0, (long long)(a[i] - i / days));
  }

  return done >= (long long)m;
}

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

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

  cin >> n >> m;

  long long sum = 0;

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

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

  sort(a, a + n, cmp);

  int l = 1, r = n;

  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }

  if(can(l))
    cout << l;
  else
    cout << r;
  return 0;
}


//
// Created by rvg77 on 01.03.19.
//

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 2 * (int)1e5 + 13;

int n, m;

int a[MAXN];

bool can(int days) {
  long long done = 0;
  for (int i = 0; i < n; ++i) {
    done += max((long long)0, (long long)(a[i] - i / days));
  }

  return done >= (long long)m;
}

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

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

  cin >> n >> m;

  long long sum = 0;

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

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

  sort(a, a + n, cmp);

  int l = 0, r = n;

  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }

  cout << r;
  return 0;
}


//
// Created by rvg77 on 01.03.19.
//

#include <iostream>
#include <algorithm>

using namespace std;

const long long MAXN = 2 * (long long)1e5 + 13;

long long n, m;

long long a[MAXN];

bool can(long long days) {
  long long done = 0;
  for (long long i = 0; i < n; ++i) {
    done += max((long long)0, a[i] - i / days);
  }

  return done >= m;
}

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

int main() {

  cin >> n >> m;

  long long sum = 0;

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

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

  sort(a, a + n, cmp);

  long long l = 0, r = n;

  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }

  cout << r;
  return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
using namespace std;
ifstream fi("test.txt");
ofstream fo("out.txt");
#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define ll long long
#define For(i,n) for (int(i) = 0; (i)<(n); (i)++)
#define For1(i,n) for (int(i) = 1; (i) <= (n); (i)++)
#define Forlr(i,l,r) for (int(i) = (l); (i) <= (r); (i)++)
#define Forrl(i,r,l) for (int(i) = (r); (i) >= (l); (i)--)
#define All(a) a.begin(), a.end()
#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265
#define putno return cout <<"NO", 0;
#define putyes return cout <<"YES", 0;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef map<int, int> mii;
//const ll MOD = 1e9 + 7;
const ll base = 269;
const ll ool = LLONG_MAX;
const int ooi = 1 << 30;
const int N = 1e5 + 5;
//DSU
/*
int p[ N], r[N];
void init(int n) {
	For(i, n) {
		p[i] = i;
	}
}
int get(int x) {
	if (p[x] != x) {
		p[x] = get(p[x]);
	}
	return p[x];
}
bool uni(int x, int y) {
	x = get(x); y = get(y);
	if (x == y) {
		return false;
	}
	if (r[x] >= r[y]) {
		p[y] = x;
	}
	else {
		p[x] = y;
	}
	if (r[x] == r[y]) {
		r[x]++;
	}
	return true;
}
*/

// So mu
/*
int power(int x, unsigned int y, int p)
{
	int res = 1; // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
*/

// ReadHexa
/*
bitset<16400> b[4101];
void readHexa()
{
	For(i, n)
	{
		string st;
		cin>> st;
		For(j, m/4)
		{
			int x;
			if (st[j] >= 'A' && st[j] <= 'F')
				x = st[j] - 'A' + 10;
			else x = st[j] - '0';
			for (int k = 4; k; --k, x >>= 1)
				b[i][j * 4 + k] = x & 1;
		}
	}
}
*/

// nChoosek
/*
ll nChoosek(ll n, ll k)
{
	if (k > n) return 0;
	if (k * 2 > n) k = n - k;
	if (k == 0) return 1;

	ll result = n;
	for (ll i = 2; i <= k; ++i) {
		result *= (n - i + 1);
		result /= i;
	}
	return result;
}
*/

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

/*
MIKUNO - 15/02/1999
*/
int n, m, k, t, cnt, rs1, q;
//ll n, m, q, k, pos, t, cnt, rs1, check;
ll maxx = -1e9, minn = 1e9;
const int maxn = 2*N;
const ll MOD = 1e9;
ll a[maxn], sum[maxn];
mii num;
ll check(int k)
{
	ll s = 0;
	int t = k;
	cnt = 0;
	For(i, n)
	{
		if (t == 0) cnt++;
		if (a[i] >= cnt)
		{
			s += a[i] - cnt;
			t--;
		}
		else
			break;
	}
	return s;
}
int main()
{
	fast_input();
	cin >> n >> m;
	ll s = 0;
	For(i, n)
		cin >> a[i];
	sort(a, a + n);
	int l = 1, r = n, mid;
	int rs = -1;
	while (l <= r)
	{
		mid = l + r >> 1;
		if (m <= check(mid))
			rs = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	cout << rs;
}


#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
using namespace std;
ifstream fi("test.txt");
ofstream fo("out.txt");
#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define ll long long
#define For(i,n) for (int(i) = 0; (i)<(n); (i)++)
#define For1(i,n) for (int(i) = 1; (i) <= (n); (i)++)
#define Forlr(i,l,r) for (int(i) = (l); (i) <= (r); (i)++)
#define Forrl(i,r,l) for (int(i) = (r); (i) >= (l); (i)--)
#define All(a) a.begin(), a.end()
#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265
#define putno return cout <<"NO", 0;
#define putyes return cout <<"YES", 0;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef map<int, int> mii;
//const ll MOD = 1e9 + 7;
const ll base = 269;
const ll ool = LLONG_MAX;
const int ooi = 1 << 30;
const int N = 1e5 + 5;
//DSU
/*
int p[ N], r[N];
void init(int n) {
	For(i, n) {
		p[i] = i;
	}
}
int get(int x) {
	if (p[x] != x) {
		p[x] = get(p[x]);
	}
	return p[x];
}
bool uni(int x, int y) {
	x = get(x); y = get(y);
	if (x == y) {
		return false;
	}
	if (r[x] >= r[y]) {
		p[y] = x;
	}
	else {
		p[x] = y;
	}
	if (r[x] == r[y]) {
		r[x]++;
	}
	return true;
}
*/

// So mu
/*
int power(int x, unsigned int y, int p)
{
	int res = 1; // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
*/

// ReadHexa
/*
bitset<16400> b[4101];
void readHexa()
{
	For(i, n)
	{
		string st;
		cin>> st;
		For(j, m/4)
		{
			int x;
			if (st[j] >= 'A' && st[j] <= 'F')
				x = st[j] - 'A' + 10;
			else x = st[j] - '0';
			for (int k = 4; k; --k, x >>= 1)
				b[i][j * 4 + k] = x & 1;
		}
	}
}
*/

// nChoosek
/*
ll nChoosek(ll n, ll k)
{
	if (k > n) return 0;
	if (k * 2 > n) k = n - k;
	if (k == 0) return 1;

	ll result = n;
	for (ll i = 2; i <= k; ++i) {
		result *= (n - i + 1);
		result /= i;
	}
	return result;
}
*/

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

/*
MIKUNO - 15/02/1999
*/
int n, m, k, t, cnt, rs1, q;
//ll n, m, q, k, pos, t, cnt, rs1, check;
ll maxx = -1e9, minn = 1e9;
const int maxn = 2*N;
const ll MOD = 1e9;
ll a[maxn], sum[maxn];
mii num;
ll check(int k)
{
	ll s = 0;
	int t = k;
	cnt = 0;
	For(i, n)
	{
		if (t == 0) cnt++, t = k;
		if (a[i] >= cnt)
		{
			s += a[i] - cnt;
			t--;
		}
	}
	return s;
}
int main()
{
	fast_input();
	cin >> n >> m;
	ll s = 0;
	For(i, n)
		cin >> a[i];
	sort(a, a + n );
	reverse(a, a + n);
	int l = 1, r = n, mid;
	int rs = -1;
	while (l <= r)
	{
		mid = l + r >> 1;
		if (m <= check(mid))
			rs = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	cout << rs;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#define ll long long
using namespace std;
int kept[200001];
ll second_s[200001];
int n, k;
bool poder(int MI_Val)
{
//	cout<<MI_Val<<"\n";
	int c, d, i;
	c = d = i = 0;
	memset(second_s, 0, sizeof(ll)*MI_Val);
	while(i < n && kept[i] > d)
	{
		if(c >= MI_Val)
		{
			c = 0;
			d++;
		}
//		cout<<c<<" : "<<kept[i]<<" - "<<d<<"\n";
		second_s[c]+=kept[i]-d;
		i++;
		c++;
	}
	ll D = 0;
//	cout<<"\n";
	for(i = 0; i < MI_Val; i++)
		D+=second_s[i];
//	system("pause");
	return D >= k;
}
int bynaryS(int ini, int fin)
{
	if(ini+1 >= fin)
	{
		if(poder(ini)) return ini;
		if(poder(ini+1)) return ini+1;
		return -1;
	}
	int mit = (ini+fin)/2;
	if(poder(mit)) bynaryS(ini, mit);
	else bynaryS(mit, fin);
}
int main()
{
	cin>>n>>k;
	for(int i = 0; i < n; i++)
		cin>>kept[i];
	sort(kept, kept+n);
	reverse(kept, kept+n);
	cout<<bynaryS(1, n);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#define ll long long
using namespace std;
int kept[200001];
ll second_s[200001];
int n, k;
bool poder(int MI_Val)
{
	int c, d, i;
	c = d = i = 0;
	memset(second_s, 0, sizeof(ll)*MI_Val);
	while(i < n && kept[i] > d)
	{
		if(c >= MI_Val)
		{
			c = 0;
			d++;
		}
		second_s[c]+=kept[i]-d;
		i++;
		c++;
	}
	ll D = 0;
	for(i = 0; i < MI_Val; i++)
		D+=second_s[i];
	return D >= k;
}
int bynaryS(int ini, int fin)
{
	if(ini+1 >= fin)
	{
		if(poder(ini)) return ini;
		if(poder(ini+1)) return ini+1;
		return -1;
	}
	int mit = (ini+fin)/2;
	if(poder(mit)) bynaryS(ini, mit);
	else bynaryS(mit, fin);
}
int main()
{
	cin>>n>>k;
	for(int i = 0; i < n; i++)
		cin>>kept[i];
	sort(kept, kept+n);
	cout<<bynaryS(1, n);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#define ll long long
using namespace std;
int kept[200001];
int n, k;
bool poder(int MI_Val)
{
	int c, d, i;
	c = d = i = 0;
	ll second_s[MI_Val+1];
	memset(second_s, 0, sizeof(second_s));
	while(i < n && kept[i] > d)
	{
		if(c >= MI_Val)
		{
			c = 0;
			d++;
		}
		second_s[c]+=kept[i]-d;
		i++;
		c++;
	}
	ll D = 0;
	for(int i = 0; i < MI_Val; i++)
		D+=second_s[i];
	return D >= k;
}
int bynaryS(int ini, int fin)
{
	if(ini+1 >= fin)
	{
		if(poder(ini)) return ini;
		if(poder(ini+1)) return ini+1;
		return -1;
	}
	int mit = (ini+fin)/2;
	if(poder(mit)) bynaryS(ini, mit);
	else bynaryS(mit, fin);
}
int main()
{
	cin>>n>>k;
	for(int i = 0; i < n; i++)
		cin>>kept[i];
	sort(kept, kept+n);
	cout<<bynaryS(1, n);
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

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

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

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

    sort(arr, arr+n, cmp);

    int sum = 0;
    int count = 0;
    while (sum < m && count <= n) {
        sum = 0;
        count++;
        for (int i = 0; i < n; i++)
            sum += max(0, arr[i] - i/count);
    }
    cout << ((count <= n) ? count : -1);

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

typedef long long ll;

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

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

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

    sort(arr, arr+n, cmp);

    int r = n+1, l = 0;

    ll sum = 0;
    while (r - l > 1) {
        int c = (r+l) / 2;
        sum = 0;
        for (int i = 0; i < n; i++)
            sum += max(0, arr[i] - i/c);
        if (sum >= m) r = c;
        else l = c;
    }
    cout << ((r <= n) ? r : -1);

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

typedef long long ll;

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

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

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

    sort(arr, arr+n, cmp);

    int r = n+1, l = 0;

    ll sum = 0;
    while (r - l > 1) {
        int c = (r+l) / 2;
        sum = 0;
        for (int i = 0; i < n; i++)
            sum += max(0, arr[i] - i/c);
        if (sum >= m) r = c;
        else l = c;
    }
    cout << ((r <= n) ? r : -1);

    return 0;
}


#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 200005;

ll n, m, mid, s, l, r, A[MAXN];

bool is_possible(ll val) {
    ll tot = 0ll;

    for (int i = 0; i < n; i++) {
        tot += max(0ll, A[i] - i / val);
    }

    return tot >= m;
}

int main() {
    scanf("%lld%lld", &n, &m);

    for (int i = 0; i < n; i++) {
        scanf("%lld", &A[i]);
        s += A[i];
    }

    sort(A, A + n, greater<ll>());

    if (s < m) {
        printf("-1\n");
        return 0;
    }

    l = 1;
    r = m;

    while (l != r) {
        mid = (l + r) / 2;

        if (is_possible(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    printf("%lld\n", l);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s > m)
				return m+1;
		}
	return s;
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	long long t = a[n - 1] * (long long(a[n - 1] - 1)) / 2;
	if (sum < m)
	{
		cout << -1;
		system("pause");
		return 0;
	}

	long long s=0;
	int l = max(m / t, 1ll);
	int r = n;
	/*for (int i = max(m/t,1ll); i <= n; i++)
	{
		s = gets(n, m, i, s,a);
		if (s >= m)
		{
			cout << i;
			return 0;
		}
		s = 0;
	}*/
	int mid = (l+r)/2;
	while (r > l)
	{
		s = gets(n, m, mid, s, a);
		if (s >= m)
		{
			r = mid;
			mid = (l + r) / 2;
		}
		else
		{
			l = mid+1;
			mid = (l + r) / 2;
		}
		s = 0;
	}
	cout << r;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s >= m)
				return m;
		}
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	long long t = a[n - 1] * (long long(a[n - 1] - 1)) / 2;
	if (sum < m)
	{
		cout << -1;
		return 0;
	}
	long long s=0;
	for (int i = m/t; i <= n; i++)
	{
		s = gets(n, m, i, s,a);
		if (s >= m)
		{
			cout << i;
			return 0;
		}
		s = 0;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s >= m)
				return m;
		}
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	long long t = a[n - 1] * (long long(a[n - 1] - 1)) / 2;
	if (sum < m)
	{
		cout << -1;
		return 0;
	}
	long long s=0;
	for (int i = max(m/t,1ll); i <= n; i++)
	{
		s = gets(n, m, i, s,a);
		if (s >= m)
		{
			cout << i;
			return 0;
		}
		s = 0;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s >= m)
				return m;
		}
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	if (sum < m)
	{
		cout << -1;
		return 0;
	}
	long long s=0;
	for (int i = 1; i <= n; i++)
	{
		s = gets(n, m, i, s,a);
		if (s >= m)
		{
			cout << i;
			return 0;
		}
		s = 0;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s >= m)
				return m;
		}
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	long long t = a[n - 1] * (long long(a[n - 1] - 1)) / 2;
	if (sum < m)
	{
		cout << -1;
		return 0;
	}
	if (sum == m)
	{
		cout << n;
		return 0;
	}
	long long s=0;
	for (int i = max(m/t,1ll); i <= n; i++)
	{
		s = gets(n, m, i, s,a);
		if (s >= m)
		{
			cout << i;
			return 0;
		}
		s = 0;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s > m)
				return m+1;
		}
	return s;
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	long long t = a[n - 1] * (long long(a[n - 1] - 1)) / 2;
	if (sum < m)
	{
		cout << -1;
		return 0;
	}

	long long s=0;
	int l = max(m / t, 1ll);
	int r = n;

	int mid = (l+r)/2;
	while (r > l)
	{
		s = gets(n, m, mid, s, a);
		if (s >= m)
		{
			r = mid;
			mid = (l + r) / 2;
		}
		else
		{
			l = mid+1;
			mid = (l + r) / 2;
		}
		s = 0;
	}
	cout << r;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s >= m)
				return m;
		}
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	if (sum < m)
	{
		cout << -1;
		system("pause");
		return 0;
	}
	long long s=0;
	for (int i = 1; i <= n; i++)
	{
		s = gets(n, m, i, s,a);
		if (s >= m)
		{
			cout << i;
			system("pause");
			return 0;
		}
		s = 0;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int r = 1e9 + 10;

long long gets(int n,int m,int d,long long s,vector<int> a)
{
	int i = n - 1;
	for(int k=0;;k++)
	for (int j = 0; j < d; j++)
		{
			if (i>=0&&a[i] > k)
			{
				s += a[i]-k;
				i--;
			}
			else
				return s;
			if (s >= m)
				return m;
		}
}
int main()
{
	vector<int> a;
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a.push_back(b);
		sum += a[i];
	}
	sort(a.begin(), a.end());
	long long t = a[n - 1] * (long long(a[n - 1] - 1)) / 2;
	if (sum < m)
	{
		cout << -1;
		return 0;
	}
	long long s=0;
	for (int i = m/t+1; i <= n; i++)
	{
		s = gets(n, m, i, s,a);
		if (s >= m)
		{
			cout << i;
			return 0;
		}
		s = 0;
	}
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

bool comp(int &lhs, int &rhs) { return lhs > rhs; }

bool check(vector<int> &coffee, int &x, int &k, int &n)
{
	int pages = 0;
	int i = 0;
	while (pages < k && i < n)
	{
		pages += max(0, coffee[i] - i / x);
		i++;
	}
	if (pages >= k)
		return true;
	else
		return false;
}

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> coffee(n);
	for (int i = 0; i < n; i++)
		cin >> coffee[i];

	sort(coffee.begin(), coffee.end(), &comp);

	int left = 1, right = k;
	int x;
	bool res;
	while (right - left > 0)
	{
		x = (right + left) / 2;
		if (check(coffee, x, k, n))
			right = x;
		else
			left = x + 1;
	}

	if (check(coffee, left, k, n))
		cout << left;
	else
		cout << -1;
}


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

int coffee[200005] ={0};
long long N,M;

bool Verify(int d)
{
	long long total = 0;
	for(int i=1;i<=N;i++)
		total += max(0,coffee[i] - (i-1)/d);
	return total >= M;
}

int main()
{
	int i,ans=-1;
	scanf("%lld%lld",&N,&M);
	for(i=1;i<=N;i++)
		scanf("%d",&coffee[i]);
	sort(coffee+1,coffee+N+1,greater<int>());
	long long l=1,r=min(M,N);
	while(l<=r)
	{
		int mid = (l+r)/2;
		if(Verify(mid))
		{
			ans = mid;
			r = mid - 1;
		}
		else
		{
			l = mid + 1;
		}
	}
	printf("%d",ans);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
inline int mmin(int a, int b) { return (a > b) ? b : a; }
inline int mmax(int a, int b) { return (a < b) ? b : a; }
//int x_1, y_1, x_2, y_2, distx, disty, min_dist, min_i;

int n, m;
vector<int> cofs;

// false if needs more days; true if works in present
bool work(int days) {
	long long d = 0;
	for (int i = 0; i < n; i++) {
		d += mmax(0, cofs[n - 1 - i] - (i / days));
	}
	if (d >= m) return true;
	return false;
}

int b_s(int low, int high) {
	if (low == high) return low;
	if (low + 1 == high) {
		if (work(low)) return low;
		return high;
	}
	int mid = (low + high) / 2;
	if (work(mid)) { return b_s(low, mid); }
	else { return b_s(mid + 1, high); }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//int n, m;
	cin >> n >> m;
	cofs.resize(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> cofs[i];
		sum += cofs[i];
	}
	if (sum < m) {
		cout << "-1";
		return 0;
	}
	else if (sum == m) {
		cout << n;
		return 0;
	}
	sort(cofs.begin(), cofs.end());
	cout << b_s(1, n - 1);
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
inline int mmin(int a, int b) { return (a > b) ? b : a; }
inline int mmax(int a, int b) { return (a < b) ? b : a; }
//int x_1, y_1, x_2, y_2, distx, disty, min_dist, min_i;

int n, m;
vector<int> cofs;

// false if needs more days; true if works in present
bool work(int days) {
	long long d = 0;
	for (int i = 0; i < n; i++) {
		d += mmax(0, cofs[n - 1 - i] - (i / days));
	}
	if (d >= m) return true;
	return false;
}

int b_s(int low, int high) {
	if (low == high) return low;
	if (low + 1 == high) {
		if (work(low)) return low;
		return high;
	}
	int mid = (low + high) / 2;
	if (work(mid)) { return b_s(low, mid); }
	else { return b_s(mid + 1, high); }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//int n, m;
	cin >> n >> m;
	cofs.resize(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> cofs[i];
		sum += cofs[i];
	}
	if (sum < m) {
		cout << "-1";
		return 0;
	}
	else if (sum == m) {
		cout << n;
		return 0;
	}
	sort(cofs.begin(), cofs.end());
	cout << b_s(1, n);
}


#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
#define pi acos(-1)
using namespace std;

int n, m, a[105];
bool cmp(int x, int y)
{
	return x > y;
}

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

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


#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
#define pi acos(-1)
using namespace std;

int n, m, a[105];
bool cmp(int x, int y)
{
	return x > y;
}

bool check(int x)
{
	int i, k = 0;
	long long ans = 0;
	for (i = 0; i < n / x; ++i)
		for (int j = 0; j < x; ++j, ++k)
			ans += max(0, a[k] - i);
	for (; k < n; ++k) ans += max(0, a[k] - i);
	return ans >= m;
}

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


#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
#define pi acos(-1)
using namespace std;

int n, m, a[105];
bool cmp(int x, int y)
{
	return x > y;
}

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

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


#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
#define pi acos(-1)
using namespace std;

int n, m, a[200005];
bool cmp(int x, int y)
{
	return x > y;
}

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

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


#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <time.h>
#include <random>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
using namespace std;
typedef long long ll;

int n, m, a[2000100];
bool used[1000];

bool check(ll k, ll d) {
	int j = 0, l = 0;
	while (k > 0) {
		bool b = 1;
		forn(l, l + d, i) {
			if (i >= n)
				continue;
			k -= max(0, a[i] - j);
			if (a[i] - j > 0)
				b = 0;
		}
		if (b && k > 0)
			return 0;
		j++;
		l += d;
	}
	return 1;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> m;
	forn(0, n, i)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	ll l = 0, r = 20000000;
	while (r - l > 1){
		ll med = (r + l) / 2;
		if (check(m, med))
			r = med;
		else
			l = med;
	}
	if (check(m, l))
		cout << l;
	else if (check(m, r))
		cout << r;
	else cout << -1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <time.h>
#include <random>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
using namespace std;
typedef long long ll;

int n, m, a[2000100];
bool used[1000];

bool check(ll k, ll d) {
	int j = 0, l = 0;
	while (k > 0) {
		bool b = 1;
		forn(l, l + d, i) {
			if (i >= n)
				continue;
			k -= a[i] - j;
			if (a[i] - j > 0)
				b = 0;
		}
		if (b && k > 0)
			return 0;
		j++;
		l += d;
	}
	return 1;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> m;
	forn(0, n, i)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	ll l = 0, r = 1000000;
	while (r - l > 1){
		ll med = (r + l) / 2;
		if (check(m, med))
			r = med;
		else
			l = med;
	}
	if (check(m, l))
		cout << l;
	else if (check(m, r))
		cout << r;
	else cout << -1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <time.h>
#include <random>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
using namespace std;
typedef long long ll;

int n, m, a[2000100];
bool used[1000];

bool check(ll k, ll d) {
	int j = 0, l = 0;
	while (k > 0) {
		bool b = 1;
		forn(l, l + d, i) {
			if (i >= n)
				continue;
			k -= a[i] - j;
			if (a[i] - j > 0)
				b = 0;
		}
		if (b && k > 0)
			return 0;
		j++;
		l += d;
	}
	return 1;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> m;
	forn(0, n, i)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	ll l = 0, r = 200000000;
	while (r - l > 1){
		ll med = (r + l) / 2;
		if (check(m, med))
			r = med;
		else
			l = med;
	}
	if (check(m, l))
		cout << l;
	else if (check(m, r))
		cout << r;
	else cout << -1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <time.h>
#include <random>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
using namespace std;
typedef long long ll;

int n, m, a[2000100];
bool used[1000];

bool check(ll k, ll d) {
	int j = 0, l = 0;
	while (k > 0) {
		bool b = 1;
		forn(l, l + d, i) {
			if (i >= n)
				continue;
			k -= a[i] - j;
			if (a[i] - j > 0)
				b = 0;
		}
		if (b && k > 0)
			return 0;
		j++;
		l += d;
	}
	return 1;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> m;
	forn(0, n, i)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	ll l = 0, r = 20000000;
	while (r - l > 1){
		ll med = (r + l) / 2;
		if (check(m, med))
			r = med;
		else
			l = med;
	}
	if (check(m, l))
		cout << l;
	else if (check(m, r))
		cout << r;
	else cout << -1;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n, page;
int a[200005];
bool cmp(const int i, const int j) {
	return i > j;
}
bool iswrite(int days) {
	int consume = 0;
	int pt = 0;
	long long writen = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] - pt <= 0) break;
		writen += a[i] - pt;
		if (++consume == days) {
			pt++; consume = 0;
		}
	}
	return writen >= page;
}
int main() {
	scanf("%d%d", &n, &page);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n, cmp);
	int l = 1, r = n;
	int ans=-1;
	while (l <= r) {
		int mid = (l + r) / 2;
		if (iswrite(mid)) {
			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	printf("%d", ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n, page;
int a[200005];
bool cmp(const int i, const int j) {
	return i > j;
}
bool iswrite(int days) {
	int consume = 0;
	int pt = 0;
	int writen = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] - pt <= 0) break;
		writen += a[i] - pt;
		if (++consume == days) {
			pt++; consume = 0;
		}
	}
	return writen >= page;
}
int main() {
	scanf("%d%d", &n, &page);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n, cmp);
	int l = 1, r = n;
	int ans=-1;
	while (l <= r) {
		int mid = (l + r) / 2;
		if (iswrite(mid)) {
			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	printf("%d", ans);
	return 0;
}


#include <iostream>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <map>
#include <set>
#include <vector>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<long long, long long>
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define int long long
#define _ << " " <<
#define $ << " "
#define all(a) a.begin(), a.end()
#define srt(a) std::sort(a.begin(), a.end())
template<typename T>
vector<T> _set_to_vec(std::set<T> z)
{
	vector<T> w;
	auto it = z.begin();
	while (it != z.end())
		w.push_back(*it++);
	return w;
}

template<typename T>
void pop_front(std::vector<T>& vec)
{
	vec.erase(vec.begin());
}

vector<long long> z_function(string s) {
	long long n = (long long)s.length();
	vector<long long> z(n);
	for (long long i = 1, l = 0, r = 0; i < n; ++i) {
		if (i <= r)
			z[i] = min(r - i + 1, z[i - l]);
		while (i + z[i] < n && s[z[i]] == s[i + z[i]])
			++z[i];
		if (i + z[i] - 1 > r)
			l = i, r = i + z[i] - 1;
	}
	return z;
}
struct point {
	double x, y;
	point(double x, double y) :x(x), y(y) {};
	point() {};
};

point operator+(point a, point b) { return point(a.x + b.x, a.y + b.y); };
point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y); };
double operator*(point a, point b) { return (a.x * b.x + a.y * b.y); };

double operator^(point a, point b) { return (a.x * b.y - a.y * b.x); };
double operator%(point a, point b) { return atan2(a^b, a*b); }
double eps = 1e-13;
template<typename T>
bool equals(T a, T b)
{
	return abs(a - b) <= eps;
}
template<typename T>
int sign(T a)
{
	return a < 0 ? -1 : (a > 0 ? 1 : 0);
}
#define pt point
inline double area(pt a, pt b, pt c) {
	return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
inline char intersect_1(double a, double b, double c, double d) {
	if (a > b)  swap(a, b);
	if (c > d)  swap(c, d);
	return max(a, c) <= min(b, d);
}

char intersect(pt a, pt b, pt c, pt d) {
	return intersect_1(a.x, b.x, c.x, d.x)
		&& intersect_1(a.y, b.y, c.y, d.y)
		&& area(a, b, c) * area(a, b, d) <= 0
		&& area(c, d, a) * area(c, d, b) <= 0;
}

double pi = acos(-1.0);
double dist(point p)
{
	return sqrt(p.x * p.x + p.y*p.y);
}

bool cmpr(pt a, pt b)
{
	if (equals((a^b), (double)0))
		return dist(a) < dist(b);
	else return (a ^ b) < 0;
}
bool cmp(pt a, pt b) {
	return a.x < b.x || a.x == b.x && a.y < b.y;
}

bool cw(pt a, pt b, pt c) {
	return a.x*(b.y - c.y) + b.x*(c.y - a.y) + c.x*(a.y - b.y) < 0;
}

bool ccw(pt a, pt b, pt c) {
	return a.x*(b.y - c.y) + b.x*(c.y - a.y) + c.x*(a.y - b.y) > 0;
}

void convex_hull(vector<pt> & a) {
	if (a.size() == 1)  return;
	sort(a.begin(), a.end(), &cmp);
	pt p1 = a[0], p2 = a.back();
	vector<pt> up, down;
	up.push_back(p1);
	down.push_back(p1);
	for (size_t i = 1; i < a.size(); ++i) {
		if (i == a.size() - 1 || cw(p1, a[i], p2)) {
			while (up.size() >= 2 && !cw(up[up.size() - 2], up[up.size() - 1], a[i]))
				up.pop_back();
			up.push_back(a[i]);
		}
		if (i == a.size() - 1 || ccw(p1, a[i], p2)) {
			while (down.size() >= 2 && !ccw(down[down.size() - 2], down[down.size() - 1], a[i]))
				down.pop_back();
			down.push_back(a[i]);
		}
	}
	a.clear();
	for (size_t i = 0; i < up.size(); ++i)
		a.push_back(up[i]);
	for (size_t i = down.size() - 2; i > 0; --i)
		a.push_back(down[i]);
}

typedef string str;

template<typename T>
inline istream &operator >>(istream &in, vec<T> &a) {
	for (int i = 0; i < a.size(); i++) in >> a[i];
	return in;
}

template<typename T>
inline ostream &operator <<(ostream &out, vec<T> &a) {
	for (int i = 0; i < a.size(); i++) out << a[i] << " ";
	return out;
}

template<typename T, typename E>
inline istream &operator >>(istream &in, pair<T, E> &a) {
	in >> a.first >> a.second;
	return in;
}

template<typename T>
T gcd(T a, T b) {
	T c;
	while (b) {
		c = a % b;
		a = b;
		b = c;
	}
	return a;
}

template<typename T>
T lcm(T a, T b) {
	return (a / gcd(a, b)) * b;
}

vector<int> prefix_function(string s) {
	int n = (int)s.length();
	vector<int> pi(n);
	for (int i = 1; i < n; ++i) {
		int j = pi[i - 1];
		while (j > 0 && s[i] != s[j])
			j = pi[j - 1];
		if (s[i] == s[j])  ++j;
		pi[i] = j;
	}
	return pi;
}

int binpow(int a, int n) {
	if (n == 0)
		return 1;
	if (n & 1)
		return binpow(a, n - 1) * a;
	else {
		int b = binpow(a, n >> 1);
		return b * b;
	}
}

typedef vec<vi> matrix;

matrix operator*(matrix & a, matrix &b) {
	matrix m;
	int cx = a[0].size(), cy = b.size();
	m.resize(cx);
	for (int i = 0; i < cx; i++)
		m[i].resize(cy);
	for (int i = 0; i < cx; i++) {
		for (int j = 0; j < cy; j++) {
			int res = 0;
			for (int p = 0; p < b[0].size(); p++)
				res += a[i][p] * b[p][j];
			m[i][j] = res;
		}
	}
	return m;
}

matrix pow(matrix &a, int b) {
	if (b == 1)
		return a;
	if (b & 1)
	{
		auto r = pow(a, b - 1);
		r = r * a;
		return r;
	}
	else {
		auto r = pow(a, b / 2);
		r = r * r;
		return r;
	}
}
vi a;
int n, m;
bool check(int x) {
	ll ans = 0;
	for (int j = 0; j <= n; j += x)
		for (int i = 1; i <= x && i + j <= n; i++) ans += max(a[i + j] - j / x, 0ll);
	return ans >= m;
}

inline void solve() {

	cin >> n >> m;
	a.resize(n);
	cin >> a;
	a.push_back(2e9);
	srt(a);
	reverse(all(a));
	int l = 1, r = n, ans = 0;
	while (l <= r) {
		int md = (l + r) / 2;
		if (check(md))
			r = md - 1, ans = md;
		else l = md + 1;
	}
	cout << (ans ? ans : -1);

}

int32_t main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	int k;
	cin >> k;
}


#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int n, m;
int const NMAX = 2e5;
ll coffee[NMAX];

ll max(ll a, ll b){
  if(a >= b){
    return a;
  }else{
    return b;
  }
}

bool canFinish(ll days) {
  ll caf = 0;
  for(int i=0; i<n; i++){ //when i == days
    caf += max(0, coffee[n - 1 - i] - i/days);
  }
  return(caf >= m);
}

int binarySearch(int from, int to) {
  if(from < to) {
    int guess = (from + to) / 2; //(1, 2) => 1
    if(canFinish(guess)) {
      return binarySearch(from, guess); //(1, 1)
    } else {
      return binarySearch(guess+1, to);
    }
  }
  return from;
}

int main() {
    cin >> n >> m;
    ll sum = 0;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        coffee[i] = x;
        sum += x;
    }
    sort(coffee, coffee + n);
    if(sum < m){
        cout << -1;
    } else {
        cout << binarySearch(1, n);
    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
typedef unsigned long long ull;

ull n, m;
ull const NMAX = 1e9;
ull coffee[NMAX];

bool canFinish(ull days){
    ull caf = 0;
    for(ull i=0; i<n; i++){
        caf += coffee[n-1-i];
        caf -= i;
        if(caf >= m){
            return true;
        }
    }
    return false;
}

ull binarySearch(ull from, ull to) {
  if(from < to) {
    ull guess = (from + to) / 2; //(1, 2) => 1
    if(canFinish(guess)) {
      return binarySearch(from, guess); //(1, 1)
    } else {
      return binarySearch(guess+1, to);
    }
  }
  return from;
}

int main() {
    cin >> n >> m;
    ull sum = 0;
    for(ull i=0; i<n; i++){
        int x;
        cin >> x;
        coffee[i] = x;
        sum += x;
    }
    sort(coffee, coffee+n);
    if(sum < m){
        cout << -1;
    } else {
        cout << binarySearch(1, n);
    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
typedef unsigned long long ull;

ull n, m;
ull const NMAX = 2e5;
ull coffee[NMAX];

bool canFinish(ull days){
    ull caf = 0;
    for(ull i=0; i<n; i++){
        caf += coffee[n-1-i];
        caf -= i;
        if(caf >= m){
            return true;
        }
    }
    return false;
}

ull binarySearch(ull from, ull to) {
  if(from < to) {
    ull guess = (from + to) / 2; //(1, 2) => 1
    if(canFinish(guess)) {
      return binarySearch(from, guess); //(1, 1)
    } else {
      return binarySearch(guess+1, to);
    }
  }
  return from;
}

int main() {
    cin >> n >> m;
    ull sum = 0;
    for(ull i=0; i<n; i++){
        int x;
        cin >> x;
        coffee[i] = x;
        sum += x;
    }
    sort(coffee, coffee + n);
    if(sum < m){
        cout << -1;
    } else {
        cout << binarySearch(1, n);
    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int n, m;
int const NMAX = 2e5;
ll coffee[NMAX];

bool canFinish(ll days) {
    ll caf = 0;
    for(int i=0; i<n; i++) { //array indices always int
        caf += coffee[n - 1 - i];
        caf -= i;
        if(caf >= m){
            return true;
        }
    }
    return false;
}

int binarySearch(int from, int to) {
  if(from < to) {
    int guess = (from + to) / 2; //(1, 2) => 1
    if(canFinish(guess)) {
      return binarySearch(from, guess); //(1, 1)
    } else {
      return binarySearch(guess+1, to);
    }
  }
  return from;
}

int main() {
    cin >> n >> m;
    ull sum = 0;
    for(ull i=0; i<n; i++){
        int x;
        cin >> x;
        coffee[i] = x;
        sum += x;
    }
    sort(coffee, coffee + n);
    if(sum < m){
        cout << -1;
    } else {
        cout << binarySearch(1, n);
    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

long long N, M;
long long a[(int)2e5];

long long count(long long K)
{
	long long res = 0;
	for (long long i = 0; i <= N / K; i++)
	{
		for (long long j = K * i; j < min(N, K*(i + 1)); j++)
			res += max(0LL, a[j] - i);
	}
	return res;
}

//long long count(long long K)
//{
//	long long sum = 0; // there can be a bug
//	for (int j = 0; j < N; ++j) {
//		sum += max(a[j] - j / K, 0LL);
//	}
//	return sum;
//}

int solve()
{
	int l = 1, r = N;
	while (l < r)
	{
		int med = (l + r) / 2;
		long long res = count(med);
		if (res < M)
			l = med+1;
		else
			r = med;
	}
	if (l > r) swap(l, r);
	if (count(l) >= M)
		return l;
	if (count(r) >= M)
		return r;
	return -1;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#endif
	cin >> N >> M;
	for (int i = 0; i < N; i++)
		cin >> a[i];
	sort(a, a + N, [](int a, int b)->bool { return a > b; });
	cout << solve();
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAX_N = 1e5+50;
const int MOD = 1e9+7;
LL a[2*MAX_N];
int check(LL temp,LL m,LL n)
{
	LL top=0,k=0,ans=0;
	for(int i=n-1; i>=0; i--)
	{
		ans += max((LL)0,a[i]-k);
		top++;
		if(ans>=m)
		{
			return 1;
		}
		if(top == temp)
		{
			k++;
			top = 0;
		}
	}
	return 0;
}
int main(void)
{
	LL n,m;
	scanf("%lld %lld",&n,&m);
	for(int i=0; i<n; i++) scanf("%lld",&a[i]);
	sort(a,a+n);
	LL ans = 0;
	for(int i=0; i<n; i++)
		ans += a[i];
	if(ans<m) printf("-1");
	else if(ans == m) printf("%lld",n);
	else
	{
		LL l = 1,r = n,res=n;
		while(l<=r)
		{
			LL temp = (l+r)/2;
			if(check(temp,m,n))
			{
				res = min(res,temp);
				r = temp-1;
			}
			else l = temp+1;
		}
		printf("%lld",res);
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int m,n;
int a[10000010];
int tmp(int a,int b)
{
	return a>b;
}
bool check(int tmp)
{
	int sum=0;
	for(int i=1,t=0;i<=m;i++)
	{
		sum+=std::max(0,(a[i]-t));//����Ҫ ���˺ܾòŷ���
		if(i%tmp==0) t++;
	}
	return sum>=n;
}
int main()
{
	int sum=0;
	scanf("%d %d",&m,&n);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",a+i);
		sum+=a[i];
	}
	sort(a+1,a+m+1,tmp);
	if(sum<n)
	{
		printf("-1");
		return 0;
	}
	int l=1,r=m+1,mid;
	while(l<r)
	{
		mid=(l+r)/2;
		if(check(mid))
		{
			r=mid;
		}
		else
		l=mid+1;
	}
	printf("%d",l);
	return 0;
 }


#include<stdio.h>
#include<algorithm>
using namespace std;
long long m,n;
long long a[10000010];
int tmp(long long a,long long b)
{
	return a>b;
}
bool check(long long tmp)
{
	long long sum=0;
	for(long long i=1,t=0;i<=m;i++)
	{
		sum+=std::max((long long)0,(a[i]-t));//����Ҫ ���˺ܾòŷ���
		if(i%tmp==0) t++;
	}
	return sum>=n;
}
int main()
{
	long long sum=0;
	scanf("%lld %lld",&m,&n);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",a+i);
		sum+=a[i];
	}
	sort(a+1,a+m+1,tmp);
	if(sum<n)
	{
		printf("-1");
		return 0;
	}
	int l=1,r=m+1,mid;
	while(l<r)
	{
		mid=(l+r)/2;
		if(check(mid))
		{
			r=mid;
		}
		else
		l=mid+1;
	}
	printf("%d",l);
	return 0;
 }


#include<stdio.h>
#include<algorithm>
using namespace std;
int m,n;
int a[10000010];
bool check(int tmp)
{
	int sum=0;
	for(int i=1,t=0;i<=m;i++)
	{
		sum+=std::max(0,(a[i]-t));//����Ҫ ���˺ܾòŷ���
		if(i%tmp==0) t++;
	}
	return sum>=n;
}
int main()
{
	int sum=0;
	scanf("%d %d",&m,&n);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",a+i);
		sum+=a[i];
	}
	sort(a+1,a+m+1);
	if(sum<n)
	{
		printf("-1");
		return 0;
	}
	int l=1,r=m+1,mid;
	while(l<r)
	{
		mid=(l+r)/2;
		if(check(mid))
		{
			r=mid;
		}
		else
		l=mid+1;
	}
	printf("%d",l);
	return 0;
 }


#include<stdio.h>
#include<algorithm>
using namespace std;
int m,n;
int a[10000010];
int tmp(int a,int b)
{
	return a>b;
}
bool check(int tmp)
{
	int sum=0;
	for(int i=1,t=0;i<=m;i++)
	{
		sum+=std::max(0,(a[i]-t));//����Ҫ ���˺ܾòŷ���
		if(i%tmp==0) t++;
	}
	return sum>=n;
}
int main()
{
	long long sum=0;
	scanf("%d %d",&m,&n);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",a+i);
		sum+=a[i];
	}
	sort(a+1,a+m+1,tmp);
	if(sum<n)
	{
		printf("-1");
		return 0;
	}
	int l=1,r=m+1,mid;
	while(l<r)
	{
		mid=(l+r)/2;
		if(check(mid))
		{
			r=mid;
		}
		else
		l=mid+1;
	}
	printf("%d",l);
	return 0;
 }


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include <fstream>
#include <set>
#include <list>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define all(g) g.begin(),g.end()
#define allr(g) g.rbegin(),g.rend()
#define re(x)   return cout<<x,0
#define in(n)for(int i=0;i<n;i++)cin>>v[i];
#define loop(n)for(int i=0;i<n;i++)
#define matar 	ios_base::sync_with_stdio(false); cin.tie(NULL);
#define me(x,v) memset(x,v,sizeof(x))
#define endl '\n'
ll GCD(ll a, ll b){ return(b == 0) ? a : GCD(b, a%b); }
ll LCM(ll a, ll b)
{
	ll temp = GCD(a, b);

	return temp ? (a / temp * b) : 0;
}
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
ll oo = 1e18;
ll const M = 1e6, N =2e5 + 7;
ll  n, m, sum, t, c, k;
int x, y,ans;
vector<int>v;
bool can(int k)
{
	c = 0;
for (int j = 0 ; j < n; j++)
		{
			c += max(v[j] - j / k, 0);
		}

		if (c >= m) return 1;
		return 0;

}
int main()
{
	matar
		cin >> n >> m;
	v.resize(n);
 in(n); sort(allr(v));
	loop(n)sum += v[i];
	if (sum < m)re(-1);

	int l = 1, r = N,mid=0;
	while (l<=r)
	{
		mid = (l + r) / 2;
		if (can(mid))
		{
			r = mid - 1;
			ans = mid;
		}
		else l = mid + 1;

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


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <set>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <math.h>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>

using namespace std;

#define ll long long
#define int long long
typedef int hv;
#define double long double
#define make(type, x) type x; cin>>x
#define make2(type, x, y) type x, y; cin>>x>>y
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z
#define make4(type, x, y, z, q) type x, y, z, q; cin>>x>>y>>z>>q
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define PPII pair<PII, int>
#define M7 1'000'000'007ll
#define M9 1'000'000'009ll
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];

const int MAXN = 200'000;
ll n, m, sm, a[MAXN];

bool check(int k) {
	int en = 0;
	for (int i = 0; en < m && i < n; ++i) {
		en += a[i] - i / k;
	}
	return en >= m;
}

void Solve() {
	cin >> n >> m;
	FOR(n) cin >> a[i];
	sort(a, a + n, [](const int&a, const int& b) {return a > b; });
	sm = accumulate(a, a + n, 0ll);
	if (m > sm) return void(cout << -1);
	int l = 1, r = n + 1;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	cout << ((l + r) >> 1);
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _SUPER_DEFINE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	Solve();
	while (!cin.eof()) {
		string s = "_";
		do getline(cin, s);
		while (!cin.eof() && !s.empty());
		if (cin.eof()) return 0;
		FOR(2) cout << endl;
		fflush(stdout);
		Solve();
	}
#else
	Solve();
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <set>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <math.h>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>

using namespace std;

#define ll long long
typedef int hv;
#define double long double
#define make(type, x) type x; cin>>x
#define make2(type, x, y) type x, y; cin>>x>>y
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z
#define make4(type, x, y, z, q) type x, y, z, q; cin>>x>>y>>z>>q
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define PPII pair<PII, int>
#define M7 1'000'000'007ll
#define M9 1'000'000'009ll
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];

const int MAXN = 200'000;
ll n, m, sm, a[MAXN];

bool check(int k) {
	int en = 0;
	for (int i = 0; en < m && i < n; ++i) {
		en += a[i] - i / k;
	}
	return en >= m;
}

void Solve() {
	cin >> n >> m;
	FOR(n) cin >> a[i];
	sort(a, a + n, [](const int&a, const int& b) {return a > b; });
	sm = accumulate(a, a + n, 0ll);
	if (m > sm) return void(cout << -1);
	int l = 1, r = n + 1;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	cout << ((l + r) >> 1);
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _SUPER_DEFINE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	Solve();
	while (!cin.eof()) {
		string s = "_";
		do getline(cin, s);
		while (!cin.eof() && !s.empty());
		if (cin.eof()) return 0;
		FOR(2) cout << endl;
		fflush(stdout);
		Solve();
	}
#else
	Solve();
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
int cmp(ll aa, ll bb)
{
	return aa > bb;
}
int main()
{
	ll n, m, a[109];
	while (scanf("%lld%lld", &n, &m) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &a[i]);
		}
		int flag=0;
		sort(a,a+n,cmp);
		for(int i=1;i<=n;i++)
		{
			ll sum=0;
			for(int j=0;j<n;j++)
			{
				sum+=max(a[j]-j/i,0);
			}
			if(sum>=m)
			{
				printf("%d\n",i);
				flag=1;
				break;
			}
		 }
		 if(!flag) printf("-1\n");
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
ll a[1000000];
int cmp(ll aa, ll bb)
{
	return aa > bb;
}
int check(ll k,ll mm,ll nn)
{
	ll sum=0;
	for(int i=0;i<nn;i++)
	{
		sum+=max(a[i]-i/k,0ll);
	}
	return sum>=mm;
}
int main()
{
	ll n, m;
	while (scanf("%lld%lld", &n, &m) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &a[i]);
		}
		int flag=0;
		sort(a,a+n,cmp);
		ll l=1,r=n,ans=inf;
		while(l<=r)
		{
			ll mid=(l+r)>>1;
			if(check(mid,m,n))
			{
				r=mid-1;
				ans=min(ans,mid);
			}
			else l=mid+1;
		}
		if(ans!=inf) printf("%lld\n",ans);
		else printf("-1\n");
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
int cmp(ll aa, ll bb)
{
	return aa > bb;
}
int main()
{
	ll n, m, a[109];
	while (scanf("%lld%lld", &n, &m) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &a[i]);
		}
		int flag=0;
		sort(a,a+n,cmp);
		for(int i=1;i<=n;i++)
		{
			ll sum=0;
			for(int j=0;j<n;j++)
			{
				sum+=max(a[j]-j/i,0ll);
			}
			if(sum>=m)
			{
				printf("%d\n",i);
				flag=1;
				break;
			}
		 }
		 if(!flag) printf("-1\n");
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
ll a[1000000];
int cmp(ll aa, ll bb)
{
	return aa > bb;
}
int main()
{
	ll n, m;
	while (scanf("%lld%lld", &n, &m) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &a[i]);
		}
		int flag=0;
		sort(a,a+n,cmp);
		for(int i=1;i<=n;i++)
		{
			ll sum=0;
			for(int j=0;j<n;j++)
			{
				sum+=max(a[j]-j/i,0ll);
			}
			if(sum>=m)
			{
				printf("%d\n",i);
				flag=1;
				break;
			}
		 }
		 if(!flag) printf("-1\n");
	}
	return 0;
}


#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>

using namespace std;
void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
	cerr << H << ' ';
	dout(T...);
}

using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<long long, long long>;

const int MAXN = 2 * 100002;
const int MAXK = 26 * 2;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ld EPS = 1e-9;
const ll INF = numeric_limits<int> ::max() / 4;
const ll MSIZE = 20;
const ld pi = acos(-1.0);
const int H = 8;

ll mult_mod(ll a, ll b)
{
	return (a * b) % MOD;
}

ll add_mod(ll a, ll b)
{
	return (a + b) % MOD;
}

void precalc()
{
}

vector<ll> inp;
int n, m;

bool check(int value)
{
	ll acc = 0;
	int ans = 0;
	int ind = 0;

	while ( ind < n && acc < m)
	{
		acc += max(0ll, inp[ind] - (ind / value));

		ind++;
	}

	return acc >= m;
}

void solve()
{

	cin >> n >> m;

	for (int i = 0; i < n; ++i)
	{
		ll curr;
		cin >> curr;
		inp.push_back(curr);
	}

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

	int left = 0;
	int right = n + 1;

	while (right - left > 1)
	{
		int m = (left + right) >> 1;
		if (check(m))
		{
			right = m;
		}
		else
		{
			left = m;
		}
	}

	if (right == n + 1)
	{
		cout << -1;
		return;
	}
	cout << right;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(20);
#ifdef LOCAL
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	precalc();
	solve();
#ifdef LOCAL
	cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}


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

int n, a[200011];
long long m;

int cmp(long long a, long long b) {
	if (a > b)return 1;
	else return 0;
}

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

void binary() {
	int l = 1, r = n;
	while (r - l > 1) {
		int mid = (l + r)/2;
		if (check(mid)) r = mid;
		else l = mid;
	}
	if (check(l)) printf("%d\n", l);
	else if (check(r)) printf("%d\n", r);
	else printf("-1\n");
}

int main(){
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n, cmp);
	binary();
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
__int64 a[250010];
__int64 n,m;
bool cmp(__int64 x,__int64 y)
{
	return x>=y;
}

__int64 max(__int64 x,__int64 y)
{
	return x>y?x:y;
}
__int64 ok(__int64 x)
{
	__int64 i;
	__int64 sun=0;
	__int64 tian=0;
	__int64 sum=0;
	for(i=0;i<n;i++)
	{
		sum+=max(0,a[i]-sun);
		tian++;
		if(tian==x) tian=0,sun++;
	}
	if(sum>=m) return 1;
	return 0;
}
int main ()
{
	__int64 i;
	while(~scanf("%I64d%I64d",&n,&m))
	{
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		sort(a,a+n,cmp);
		__int64 l=1;
		__int64 r=n;
		__int64 mid;
		__int64 ans=-1;
		while(r>=l)
		{
			mid=(l+r)/2;  //天数；
			if(ok(mid))
			{
				r=mid-1;
				ans=mid;
			}
			else
				l=mid+1;
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <iostream>
#include <vector>
#include<iomanip>
#include <cstring>
#include <string.h>
#include <iterator>
#include<math.h>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <limits.h>
#include <string>
#include <bitset>
#include <map>
#include <numeric>

#define endl cout<<"\n"
#define lli long long int

using namespace std;

//fast-exponentiation-lli
lli expo_fast(lli a, lli b) {
	a = a;
	lli result = 1;
	while (b) {
		//multiplyint(tos(result), a);
		if (b & 1)result = (result * a);
		b >>= 1;
		a = (a*a);
	}
	return (result);
}

void take_in(vector<lli> *arr) {
	for (int i = 0; i < arr->size(); i++)cin >> (*(arr))[i];
}

void disp_arr(vector<lli>* arr) {
	for (int i = 0; i < arr->size(); i++)cout << (*(arr))[i] << " ";
}

lli gcd(lli a, lli b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}

vector<lli> arr(200005);
bool check(int mid,int m,int n) {
	int per = m / mid;
	vector<lli> days;
	for (int i = 0; i < m%mid; i++) {
		days.push_back((m / mid) + 1);
	}
	for (int i = days.size(); i < mid; i++)days.push_back(m / mid);
	lli over = 0;
	int index = 0;
	for (lli x : days) {
		int minus_ = 0;
		lli temp_sum = 0;
		while (temp_sum < x && index<n ) {
			if (temp_sum + over >= x) {
				over -= (x - temp_sum);
				temp_sum = x;
				break;
			}
			else {
				if ((arr[index] - minus_) <= 0)break;
				temp_sum += (arr[index++] - minus_);
				minus_++;
			}
		}
		if (temp_sum < x)return false;
		over += temp_sum - x;
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> arr[i];
	sort(arr.rbegin(), arr.rend());
	lli sum = 0;
	for (int i = 0; i < n; i++) {
		sum += arr[i];
	}
	if (sum < m)cout << -1;
	else {
		int low = 1, high = n,ans=n;
		while (low <= high) {
			int mid = (low + high) / 2;
			if (check(mid, m, n)) {
				ans = mid;
				high = mid - 1;
			}
			else low = mid + 1;
		}
		cout << ans;
	}
	//system("PAUSE");
}


#include <iostream>
#include <vector>
#include<iomanip>
#include <cstring>
#include <string.h>
#include <iterator>
#include<math.h>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <limits.h>
#include <string>
#include <bitset>
#include <map>
#include <numeric>

#define endl cout<<"\n"
#define lli long long int

using namespace std;

//fast-exponentiation-lli
lli expo_fast(lli a, lli b) {
	a = a;
	lli result = 1;
	while (b) {
		//multiplyint(tos(result), a);
		if (b & 1)result = (result * a);
		b >>= 1;
		a = (a*a);
	}
	return (result);
}

void take_in(vector<lli> *arr) {
	for (int i = 0; i < arr->size(); i++)cin >> (*(arr))[i];
}

void disp_arr(vector<lli>* arr) {
	for (int i = 0; i < arr->size(); i++)cout << (*(arr))[i] << " ";
}

lli gcd(lli a, lli b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}

vector<lli> arr(200005);
bool check(int mid,int m,int n) {
	int per = m / mid;
	vector<lli> days;
	for (int i = 0; i < m%mid; i++) {
		days.push_back((m / mid) + 1);
	}
	for (int i = days.size(); i < mid; i++)days.push_back(m / mid);
	lli over = 0;
	int index = 0;
	lli sum = 0;
	int minus_ = 0;
	for (int i = 0; i < n; i++) {
		sum += (arr[i] - minus_);
		if ((i + 1) % mid == 0)minus_++;
		if (sum >= m)return true;
	}
	return false;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> arr[i];
	sort(arr.rbegin(), arr.rend());
	lli sum = 0;
	for (int i = 0; i < n; i++) {
		sum += arr[i];
	}
	if (sum < m)cout << -1;
	else {
		int low = 1, high = n,ans=n;
		while (low <= high) {
			int mid = (low + high) / 2;
			if (check(mid, m, n)) {
				ans = mid;
				high = mid - 1;
			}
			else low = mid + 1;
		}
		cout << ans;
	}
	//system("PAUSE");
}


//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stdio.h>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#define f(n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2e9
#define MOD 1000000007  //998244353
#define eps 0.00000001
#define pi 3.1415926535

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {   //a/k=a*inv(k) divizion with MOD q^-1
	return binPow(a, MOD - 2);
}

//**************************************START*****************************

int main() {
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	vector<ll>a(n);
	vector<ll>prefix(n+2);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.rbegin(), a.rend());
	for (int i = 1; i <= n; i++) {
		prefix[i] = prefix[i - 1] + a[i - 1];

	}

	ll ans = 1e9;
	int test = 70;
	int l = 1, r = fmaxl(n, 2);
	while (test > 0) {
		test--;
		ll day = (l + r) / 2;
		ll cnt = 0;
		cnt = prefix[day];
		//cout << cnt <<" "<<day<< endl;
		if (cnt >= m) {
			ans = fminl(ans, day);
			r = day; continue;
		}

		ll ost = n - day;
		//	cout << endl;
		ll rofl = 0;
		for (int i = day; i <= n - 1; i++) {
			if (i%day == 0)rofl++;
			cnt += fmaxl((a[i] - rofl),0);
			//cout << a[i]-rofl<< endl;
			//cout << sorted[i][fminl((i + 1) * day, n)] << " " << sorted[i][fminl(i*day, n)] << endl;
		}
		if (cnt >= m) {
			ans = fminl(ans, day);
			r = day;
		}
		else {
			l = day+1;
		}
	}
	if (prefix[n] < m)ans = -1;
	cout << ans;
}


#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>

#include<deque>
#define pi 3.1415926535
#include<chrono>

#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>

using namespace std;
ll n;
ll ncr(ll n, ll r)
{
    ll i, ans = 1, k = 0;
    if (r == 0)
        return 1;
    else if (n < r)
        return 0;
    for (i = n; i >= n - r + 1; i--)
    {
        ans *= i;
        ans /= n - i + 1;
    }

    return ans;

}

void max_heapify(int a[100], int i)
{
    int l, r, largest = i;
    l = 2 * i + 1;
    r = 2 * i + 2;
    if (l<n && a[l]>a[i])
        largest = l;
    if (r<n && a[r]>a[l])
        largest = r;
    if (largest != i)
    {
        int k;
        k = a[i];
        a[i] = a[largest];
        a[largest] = k;
        max_heapify(a, largest);
    }

}
int power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

bool square(ll n)
{
    double x;
    x = sqrt(n);
    if (x == floor(x))
        return true;
    else return false;
}

bool prime(ll n)
{
    ll i;
    for (i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

ll modi(ll a, ll m)
{
    return power(a, m - 2, m);

}
void kmp(string s, ll p[]) {
    int n = (int)s.length();
    p[0] = 0;
    for (int i = 1; i < n; i++) {
        int j = p[i - 1];
        while (j > 0 && s[i] != s[j])
            j = p[j - 1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
    }

}
void zfunc(string s, ll z[]) {

    ll n = (ll)s.length();
    z[0] = 0;
    for (ll i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min(r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }

}
struct pair_hash {
    size_t operator()(const pair<int, int>& p) const noexcept {
        return hash<ll>() ((((ll)p.first) << 32) | ((ll)p.second));
    }
};

bool palin(string s) {
    ll i, n;
    n = s.length();
    for (i = 0; i <= n / 2; i++) {
        if (s[i] != s[n - i - 1]) {
            return false;
        }
    }
    return true;
}
ll sum(ll n) {
    ll i;
    i = n;
    ll sum = 0;
    while (i > 0) {
        sum += i % 10;
        i = i / 10;
    }
    return sum;
}

ll nCr(ll n, ll r, ll p, ll fac[])
{

    if (r == 0)
        return 1;
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;

    return (fac[n] * modi(fac[r], p) % p *
        modi(fac[n - r], p) % p) % p;
}

ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll mod(string num, ll a)
{

    ll res = 0;

    for (ll i = 0; i < num.length(); i++)
        res = (res * 10 + (ll)num[i] - '0') % a;

    return res;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll parent[1000], sizer[1000];
ll findset(ll a) {
    if (a == parent[a]) {
        return a;
    }
    parent[a] = findset(parent[a]);
    return parent[a];
}

void unionset(ll a, ll b) {
    a = findset(a);
    b = findset(b);
    if (sizer[a] < sizer[b]) {
        swap(a, b);
    }
    sizer[b] += sizer[a];
    parent[b] = a;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll n, m;
        cin >> n >> m;
        vector<ll> v(n);
        for (i = 0; i < n; i++) {
            cin >> v[i];
        }
        sort(v.rbegin(), v.rend());

        ll lo = 1, hi = n, mid;
        ll ans = -1;
        while (lo <= hi) {
            mid = (lo + hi) / 2;
            ll sum = 0;
            for ( j = 0; j < n; ++j) {
                sum += max(v[j] - j / mid, 0LL);
            }
            if (sum >= m) {
                ans = mid;
                hi = mid - 1;
            }
            else {
                lo = mid + 1;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

vector <int> a;
int n, b;

bool f(int i){
	long long s = 0;
	for (int j = 0; j < n; j++){
		s += max(0, a[j] - j / i);
	}
	return s >= b;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n >> b;
	a=vector <int> (n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
		//if (a[i] == 1) o++;
	}
	sort(a.rbegin(), a.rend());
	int l = 1, r = n;
	while (r - l > 1){
		int m = (l + r) / 2;
		if (f(m)){
			r = m;
		}
		else l = m;
	}
	if (f(l)) cout << l;
	else if (f(r)) cout << r;
	else cout << -1;
	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL a[N], n, k;

bool ok(int mid) {

	LL ret = 0, cnt = 0, cnt1 = 1;
	for (int i = 1;i <= n;i++) {

		if (cnt == n / mid)cnt = 0, cnt1++;
		if (cnt1 == mid)break;
		ret += max(a[i] - cnt, 0ll), cnt++;
	}

	cnt = 0;
	for (int i = n / mid*(mid - 1) + 1;i <= n;i++)
		ret += max(a[i] - cnt, 0ll), cnt++;

	return ret >= k;
}

int main()
{
	LL  sum = 0;
	scanf("%lld%lld", &n, &k);

	for (int i = 1;i <= n;i++)
		cin >> a[i], sum += a[i];

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

	LL ans = 1, cnt = 0, d = sum - k;

	if (d < 0) {
		puts("-1");
		return 0;
	}

	int l = 1, r = n;

	while (l < r) {

		int mid = (l + r) / 2;
		if (ok(mid))r = mid;
		else l = mid + 1;
	}

	cout << l << endl;
	cin >> n;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL a[N], n, k;

bool ok(int mid) {

	LL ret = 0, cnt = 0, cnt1 = 0, m = n%mid;

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

		if (cnt == n / mid + (m > 0 ? 1 : 0))cnt = 0, cnt1++, m--;
		if (cnt1 == mid)break;
		ret += max(a[i] - cnt, 0ll), cnt++;
	}

	/*cnt = 0;
	for (int i = n / mid*(mid - 1) + 1;i <= n;i++)
		ret += max(a[i] - cnt, 0ll), cnt++;*/

	return ret >= k;
}

int main()
{
	LL  sum = 0;
	scanf("%lld%lld", &n, &k);

	for (int i = 1;i <= n;i++)
		cin >> a[i], sum += a[i];

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

	LL ans = 1, cnt = 0, d = sum - k;

	if (d < 0) {
		puts("-1");
		return 0;
	}

	int l = 1, r = n;

	while (l < r) {

		int mid = (l + r) / 2;
		if (ok(mid))r = mid;
		else l = mid + 1;
	}

	cout << l << endl;
	cin >> n;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL a[N], n, k;

bool ok(int mid) {

	LL ret = 0, cnt = 0, cnt1 = 1;
	for (int i = 1;i <= mid - 1;i++)
		ret += a[i];

	for (int i = mid;i <= n;i++)
		ret += max(a[i] - cnt, 0ll), cnt++;

	/*for (int i = 1;i <= n;i++) {

		if (cnt == n / mid)cnt = 0, cnt1++;
		if (cnt1 == mid)break;
		ret += max(a[i] - cnt, 0ll), cnt++;
	}

	cnt = 0;
	for (int i = n / mid*(mid - 1) + 1;i <= n;i++)
		ret += max(a[i] - cnt, 0ll), cnt++;
	*/
	return ret >= k;
}

int main()
{
	LL  sum = 0;
	scanf("%lld%lld", &n, &k);

	for (int i = 1;i <= n;i++)
		cin >> a[i], sum += a[i];

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

	LL ans = 1, cnt = 0, d = sum - k;

	if (d < 0) {
		puts("-1");
		return 0;
	}

	int l = 1, r = n;

	while (l < r) {

		int mid = (l + r) / 2;
		if (ok(mid))r = mid;
		else l = mid + 1;
	}

	cout << l << endl;
	cin >> n;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL a[N];

int main()
{
	LL n, k, sum = 0;
	scanf("%lld%lld", &n, &k);

	for (int i = 1;i <= n;i++)
		cin >> a[i], sum += a[i];

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

	LL ans = 1, cnt = 0, d = sum - k;

	if (d < 0) {
		puts("-1");
		return 0;
	}

	sum = 0;
	for (int i = 1;i <= n;i++)
		if (sum >= k)break;
		else
			if (cnt <= d&&a[i]>cnt)d -= cnt, sum += a[i] - cnt, cnt++;
			else cnt = 1, sum += a[i], ans++;

		cout << ans << endl;
		cin >> n;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL a[N], n, k;

bool ok(int mid) {

	LL ret = 0, cnt = 0, cnt1 = 0, m = n%mid;

	for (int i = 1;i <= n;i++)
		ret += max(0ll, a[i] - (i - 1) / mid);

	return ret >= k;
}

int main()
{
	LL  sum = 0;
	scanf("%lld%lld", &n, &k);

	for (int i = 1;i <= n;i++)
		cin >> a[i], sum += a[i];

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

	LL ans = 1, cnt = 0, d = sum - k;

	if (d < 0) {
		puts("-1");
		return 0;
	}

	int l = 1, r = n;

	while (l < r) {

		int mid = (l + r) / 2;
		if (ok(mid))r = mid;
		else l = mid + 1;
	}

	cout << l << endl;
	cin >> n;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL a[N], n, k;

bool ok(int mid) {

	LL ret = 0, cnt = 0, cnt1 = 0;
	for (int i = 1;i <= n;i++) {

		if (cnt == n / mid)cnt = 0, cnt1++;
		ret += max(a[i] - cnt, 0ll), cnt++;
		if (cnt1 == mid)break;
	}

	return ret >= k;
}

int main()
{
	LL  sum = 0;
	scanf("%lld%lld", &n, &k);

	for (int i = 1;i <= n;i++)
		cin >> a[i], sum += a[i];

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

	LL ans = 1, cnt = 0, d = sum - k;

	if (d < 0) {
		puts("-1");
		return 0;
	}

	int l = 1, r = n;

	while (l < r) {

		int mid = (l + r) / 2;
		if (ok(mid))r = mid;
		else l = mid + 1;
	}

	cout << l << endl;
	cin >> n;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;

bool check(int mid, long long checkSum, vector<int> &a) {
	long long sum = 0;
	for (int i = a.size() - 1; i >= 0; i--) {
		sum += max(a[i] - ((int)a.size() - i - 1) / mid, 0);
	}

	return sum >= checkSum;
}

int main() {
	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());

	int l = 1, r = n;
	while (r - l > 1) {
		int mid = (r + l) / 2;
		if (check(mid, m, a)) {
			r = mid;
		}
		else {
			l = mid;
		}
	}

	if (check(l, m, a)) {
		cout << l;
	}
	else if (check(r, m, a)) {
		cout << r;
	}
	else {
		cout << -1;
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int a[200005];
int n, m;
bool isOk(int k)
{
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cnt += max(0, a[i] - i / k);
	}
	return cnt >= m;
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	if (!isOk(n))
		cout << -1 << endl;
	else {
		sort(a, a + n, greater<int>());
		int l = 1, r = n;
		while (l < r)
		{
			if (isOk((l + r) >> 1))
			{
				r = ((l + r) >> 1);
			}
			else l = ((l + r) >> 1) + 1;
		}
		cout << l << endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int a[200005];
int n, m;
bool isOk(int k)
{
	long long cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cnt += max(0, a[i] - i / k);
	}
	return cnt >= m;
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	if (!isOk(n))
		cout << -1 << endl;
	else {
		sort(a, a + n, greater<int>());
		int l = 1, r = n;
		while (l < r)
		{
			if (isOk((l + r) >> 1))
			{
				r = ((l + r) >> 1);
			}
			else l = ((l + r) >> 1) + 1;
		}
		cout << l << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

long long  n,m;
int a[200005];

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

bool check(int x)
{
    long long sum = 0;
    for(int i = 0; i < n; i++ )
        sum += max(0,a[i] - i/x); //向下取整的思想 i/d 必定会有d个才回加一
    //cout << sum << endl;
    return sum >= m;
}

/*
bool check(long long  mid)
{
	int k = 1;
	long long  tot = 0;
	for (int i = 0;; i++) //次
		for (int j = 0; j < mid; j++) //天
		{
			if (k > n || a[k] <= i)
				return 0;
			tot += a[k++] - i;
			if (tot >= m)
				return 1;
		}
}
*/
int main()
{

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

    if(!check(n))
    {
        cout << -1 ;
        return 0;
    }

    long long  l = 1, r = n, mid, ans = 1 << 30;
    while(l < r)
    {
        mid = l + r  >> 1;
        if(check(mid))
            r = mid ;//, ans = min(ans,mid)  ;
        else
            l = mid  + 1;
    }
    //if(ans != 1 << 30)
    //    cout << ans;
    //else
        cout << l;

/*
    long long  l = 1, r = n, mid, ans = 1 << 30;
    while(l < r)
    {
        mid = (l+r)/2;
        if(check(mid))
        {
            r = mid;
            ans = min(ans, mid);
        }

        else
            l = mid+1;
    }
    if(ans!=1<<30) cout << ans << endl;
    else cout << "-1" <<endl;
	return 0;
*/
}


#include <iostream>
#include <algorithm>

using namespace std;

long long  n,m;
int a[100005];

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

bool check(int x)
{
    long long sum = 0;
    for(int i = 0; i < n; i++ )
        sum += max(0,a[i] - i/x); //向下取整的思想 i/d 必定会有d个才回加一
    //cout << sum << endl;
    return sum >= m;
}

/*
bool check(long long  mid)
{
	int k = 1;
	long long  tot = 0;
	for (int i = 0;; i++) //次
		for (int j = 0; j < mid; j++) //天
		{
			if (k > n || a[k] <= i)
				return 0;
			tot += a[k++] - i;
			if (tot >= m)
				return 1;
		}
}
*/
int main()
{

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

    if(!check(n))
    {
        cout << -1 ;
        return 0;
    }

    long long  l = 1, r = n, mid, ans = 1 << 30;
    while(l < r)
    {
        mid = l + r  >> 1;
        if(check(mid))
            r = mid ;//, ans = min(ans,mid)  ;
        else
            l = mid  + 1;
    }
    //if(ans != 1 << 30)
    //    cout << ans;
    //else
        cout << l;

/*
    long long  l = 1, r = n, mid, ans = 1 << 30;
    while(l < r)
    {
        mid = (l+r)/2;
        if(check(mid))
        {
            r = mid;
            ans = min(ans, mid);
        }

        else
            l = mid+1;
    }
    if(ans!=1<<30) cout << ans << endl;
    else cout << "-1" <<endl;
	return 0;
*/
}


#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=2e5+7;
long long a[maxn],n,m,sum[maxn];
bool cmp(long long a,long long b)
{
    return a>b;
}
bool check(int x)
{
    if(sum[x]>=m)
        return true;
    else
    {
        int r=x+1;
        long long s=sum[x];
        while(a[r]>(r-1)/x&&r<=n)
        {
            s+=a[r]-(r-1)/x;
            if(s>=m)
                return true;
            r++;
        }
        return false;
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1,cmp);
    sum[1]=a[1];
    for(int i=2;i<=n;i++)
        sum[i]=sum[i-1]+a[i];
    int l=1,r=n;
    long long ans=-1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(check(mid))
        {
            ans=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }
    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);
    }
    return 0;
}
/*
5 8
2 3 1 1 2

4
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>

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


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>

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


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
const int maxn=100010;
typedef _int64 ll;
int max(int a,int b){return a>b?a:b;}
int a[maxn];
int n,m;
bool can(int i)
{
	int sum=0;
	for(int j = 0 ; j < n ; ++j)
		sum+=max(a[j]-j/i,0);
	return sum>=m;
}
int main()
{
#ifdef _DEBUG
	freopen("in.txt","r",stdin);
#endif
	int i;
	while(cin>>n>>m)
	{
		int sum=0;
		for( i = 0 ; i < n ; i++)
			cin>>a[i],sum+=a[i];
		sort(a,a+n,greater<int>());
		int l=1,r=n;
		while(r-l>1)
		{
			int mid = (l+r)>>1;
			if(can(mid))r=mid;
			else l=mid;
		}
		if(can(l))cout<<l<<endl;
		else if(can(r))cout<<r<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
const int maxn=100010;
typedef _int64 ll;
int max(int a,int b){return a>b?a:b;}
int a[maxn];
int n,m;
bool can(int i)
{
	ll sum=0;
	for(int j = 0 ; j < n ; ++j)
		sum+=max(a[j]-j/i,0);
	return sum>=m;
}
int main()
{
#ifdef _DEBUG
	freopen("in.txt","r",stdin);
#endif
	int i;
	while(cin>>n>>m)
	{
		for( i = 0 ; i < n ; i++)
			cin>>a[i];
		sort(a,a+n,greater<int>());
		int l=1,r=n;
		while(r-l>1)
		{
			int mid = (l+r)>>1;
			if(can(mid))r=mid;
			else l=mid;
		}
		if(can(l))cout<<l<<endl;
		else if(can(r))cout<<r<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
const int maxn=200010;
typedef _int64 ll;
int max(int a,int b){return a>b?a:b;}
int a[maxn];
int n,m;
bool can(int i)
{
	ll sum=0;
	for(int j = 0 ; j < n ; ++j)
		sum+=max(a[j]-j/i,0);
	return sum>=m;
}
int main()
{
#ifdef _DEBUG
	freopen("in.txt","r",stdin);
#endif
	int i;
	while(cin>>n>>m)
	{
		for( i = 0 ; i < n ; i++)
			cin>>a[i];
		sort(a,a+n,greater<int>());
		int l=1,r=n;
		while(r-l>1)
		{
			int mid = (l+r)>>1;
			if(can(mid))r=mid;
			else l=mid;
		}
		if(can(l))cout<<l<<endl;
		else if(can(r))cout<<r<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
const int maxn=100010;
typedef _int64 ll;
int max(int a,int b){return a>b?a:b;}
int a[maxn];
int n,m;
bool can(int i)
{
	ll sum=0;
	for(int j = 0 ; j < n ; ++j)
		sum+=max(a[j]-j/i,0);
	return sum>=m;
}
int main()
{
#ifdef _DEBUG
	freopen("in.txt","r",stdin);
#endif
	int i;
	while(cin>>n>>m)
	{
		int sum=0;
		for( i = 0 ; i < n ; i++)
			cin>>a[i],sum+=a[i];
		sort(a,a+n,greater<int>());
		int l=1,r=n;
		while(r-l>1)
		{
			int mid = (l+r)>>1;
			if(can(mid))r=mid;
			else l=mid;
		}
		if(can(l))cout<<l<<endl;
		else if(can(r))cout<<r<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}


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

long long int arr[101];

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

	long long int left = 1;
	long long int right = n;
	long long int ans = 0;
	while (left <= right)
	{
		long long int sum = 0;
		long long int mid = (left + right) / 2;
		long long int day = 0;
		long long int cnt = 0;

		for (int i = n-1; i >= 0; i--)
		{
			sum += max(arr[i] - day, (long long int)0);
			cnt++;
			if (cnt == mid)
			{
				cnt = 0;
				day++;
			}
		}

		if (sum >= m)
		{
			right = mid - 1;
		}
		else
		{
			left = mid + 1;
		}
	}
	if (left <= n)
	{
		cout << left;
	}
	else
	{
		cout << -1;
	}
	return 0;
}


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

long long int arr[200001];

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

	long long int left = 1;
	long long int right = n;
	long long int ans = 0;
	while (left <= right)
	{
		long long int sum = 0;
		long long int mid = (left + right) / 2;
		long long int day = 0;
		long long int cnt = 0;

		for (int i = n-1; i >= 0; i--)
		{
			sum += max(arr[i] - day, (long long int)0);
			cnt++;
			if (cnt == mid)
			{
				cnt = 0;
				day++;
			}
		}

		if (sum >= m)
		{
			right = mid - 1;
		}
		else
		{
			left = mid + 1;
		}
	}
	if (left <= n)
	{
		cout << left;
	}
	else
	{
		cout << -1;
	}
	return 0;
}


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

int arr[101];

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

	int left = 1;
	int right = n;
	int ans = 0;
	while (left <= right)
	{
		int sum = 0;
		int mid = (left + right) / 2;
		int day = 0;
		int cnt = 0;

		for (int i = n-1; i >= 0; i--)
		{
			sum += max(arr[i] - day, 0);
			cnt++;
			if (cnt == mid)
			{
				cnt = 0;
				day++;
			}
		}

		if (sum >= m)
		{
			right = mid - 1;
		}
		else
		{
			left = mid + 1;
		}
	}
	if (left <= n)
	{
		cout << left;
	}
	else
	{
		cout << -1;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=2e5;
long long a[MAX+5],sum[MAX+5];
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	ios::sync_with_stdio(false);
	int i,n,m,temp;
	long long sumnum,num;
	cin>>n>>m;
	for(i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++)
		sum[i]=sum[i-1]+a[i];
	//cout<<sum[n]<<endl;
	if(sum[n]<m)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	if(sum[n]==m)
	{
		cout<<n<<endl;
		return 0;
	}

	for(int day=1;day<=n;day++)
	{
		sumnum=0;
		for(i=day;i<=n;i+=day)
		{
			num=sum[i]-sum[i-day]-i/day+1;
			if(num<=0)
			{
				temp=i/day-1;
				for(int j=i-day+1;j<=i;j++)
				{
					if(a[i]>temp)
						sumnum+=temp;
					else
						break;
				}
				break;
			}
			sumnum+=num;
			if(sumnum>=m)
				break;
		}
		if(i>n)
		{
			temp=i/day-1;
			for(int j=i-day+1;j<=n;j++)
			{
				if(a[i]>temp)
					sumnum+=temp;
				else
					break;
				if(sumnum>=m)
					break;
			}
		}
		if(sumnum>=m)
		{
			cout<<day<<endl;
			return 0;
		}
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=2e5;
int a[MAX+5];
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	ios::sync_with_stdio(false);
	int i,n,m,num;
	long long sum=0;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<m)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	if(sum==m)
	{
		cout<<n<<endl;
		return 0;
	}
	sort(a,a+n,cmp);
	int left=1,right=n,minday=0;
	while(left<=right)
	{
		int day=(left+right)>>1;
		sum=0;
		for(i=0;i<n;i++)
		{
			num=a[i]-i/day;
			if(num<0)
				break;
			sum+=num;
		}
		if(sum>=m)
		{
			right=day-1;
			minday=day;
		}
		else
			left=day+1;
	}
	cout<<minday<<endl;
	return 0;
}