/*************************************************************************
    > File Name: 671B.cpp
    > Author: Triose
    > Mail: Triose@163.com
    > Created Time: 2016年06月02日 星期四 09时32分29秒
 ************************************************************************/

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for(int (i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL long long
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
template<class T> T Abss(T a, T b) { return a - b > 0 ? a - b : b - a;}
int n, m;
#define N 500010
int a[N];
int maxx, minn;
LL sum;
int get_max() {
    int low = (sum % n == 0 ? sum / n : sum / n + 1), high = maxx;
    int mid,count;
    int ans = 0;
    while(low <= high) {
	mid = (low + high) >> 1;
	count = 0;
	rep(i, n)  count += Max(0, a[i] - mid);
	if(count <= m) {
	    ans = mid;
	    high = mid - 1;
	}
	else {
	    low = mid + 1;
	}
    }
    return ans;
}
int get_min() {
    int low = minn, high = sum / n;
    int mid, count;
    int ans = 0;
    while(low <= high) {
	mid = (low + high) >> 1;
	count = 0;
	rep(i, n) count += Max(0, mid - a[i]);
	/*
	cout << "high:" << high << endl;
	cout << "mid:" << mid << endl;
	cout << "low:" << low << endl;
	*/
	if(count <= m) {
	    ans = mid;
	    low = mid + 1;
	}
	else {
	    high = mid - 1;
	}
    }
//    cout << "ans = " << ans << endl;
    return ans;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("Out.txt", "w", stdout);
#endif
    while(~sfd(n,m)) {
	maxx = -1;
	minn = INF;
	sum = 0;
	rep(i, n) {
	    sf(a[i]);
	    sum += a[i];
	    maxx = Max(maxx, a[i]);
	    minn = Min(minn, a[i]);
	}
/*
	cout << sum << endl;
	cout << "max:" << get_max() << endl;
	cout << "min:" << get_min() << endl;
*/
	pf(get_max() - get_min());
    }
    return 0;
}


/*
* Head_File
*
*  Created on: 2016年2月20日
*      Author: Triose
*/

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for(int(i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
multiset<int> ms;
multiset<int>::iterator low, high;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//	freopen("Out.txt", "w", stdout);
#endif
	int tmp;
	while(~sfd(n,m)) {
		ms.clear();
		rep(i, n) {
			sf(tmp);
			ms.insert(tmp);
		}
		while(m--) {
			low = ms.begin();
			high = ms.end();
			high--;
			if((*low) != (*high)) {
				ms.insert((*low) + 1);
				ms.insert((*high) - 1);
				ms.erase(low);
				ms.erase(high);
			}
			else {
				break;
			}
		}
		low = ms.begin(); high = ms.end(); high--;
		pf((*high) - (*low));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define sz(v) int(v.size())
#define par make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
template<class X, class Y> void amax(X& x, const Y& y){if(x < y) x = y;}
template<class X, class Y> void amin(X& x, const Y& y){if(x > y) x = y;}
typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld;
const int INF = 1e9 + 10; const ll INFL = 1e18 + 10;

int n, k;
map<int, int> cnt;
set<pair<int, int>> vv;

void add(ii p){
    if(p.se == 0) return;
    auto it = vv.lower_bound(par(p.fi, 0));
    if(it == vv.end() || it->fi != p.fi){
        vv.insert(p);
    }else{
        p.se += it->se;
        vv.erase(it);
        vv.insert(p);
    }
}

void transfer(const ii &w0, const ii &w1, int use){
    add(par(w0.fi - use/w0.se, w0.se - use%w0.se));
    add(par(w0.fi - use/w0.se - 1, use%w0.se));

    add(par(w1.fi + use/w1.se, w1.se - use%w1.se));
    add(par(w1.fi + use/w1.se + 1, use%w1.se));

    k -= use;
}

bool check(const ii &w0, const ii &w1, int limit0, int limit1, int use){
    int min0 = w0.fi - use/w0.se - (use % w0.se > 0);
    int max1 = w1.fi + use/w1.se + (use % w1.se > 0);
    if(min0 < max1 || min0 < limit0 || max1 > limit1) return false;
    return true;
}

int bfind(const ii &w0, const ii &w1, int limit0, int limit1){
    int l = 0, r = k, i = (l + r)/2;
    while(l != i && i != r){
        if(check(w0, w1, limit0, limit1, i)) l = i;
        else r = i;
        i = (l + r)/2;
    }
    for(int i = r; i >= l; i--) if(check(w0, w1, limit0, limit1, i)) return i;
    return 0;
}

void process(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int c; cin >> c;
        cnt[c]++;
    }

    for(auto p : cnt) vv.insert(p);

    while(k > 0 && sz(vv) > 1){
        ii bg = *vv.begin(); vv.erase(vv.begin());
        ii ed = *vv.rbegin(); vv.erase(prev(vv.end()));
        if(sz(vv) == 0){
            int use = bfind(ed, bg, 1, INF);
            transfer(ed, bg, use);
            if(use == 0) break;
        }else{
            int use = bfind(ed, bg, vv.rbegin()->fi, vv.begin()->fi);
            transfer(ed, bg, use);
        }
    }

    if(sz(vv) == 1) cout << 0;
    else cout << vv.rbegin()->fi - vv.begin()->fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    //~ cin.tie(nullptr);
    //~ cout << fixed; cout.precision(10);
    //~ freopen("b.in", "r", stdin);
    process();
}


#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define sz(v) int(v.size())
#define par make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
template<class X, class Y> void amax(X& x, const Y& y){if(x < y) x = y;}
template<class X, class Y> void amin(X& x, const Y& y){if(x > y) x = y;}
typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld;
const int INF = 1e9 + 10; const ll INFL = 1e18 + 10;
const int MAX = 5e5 + 10;

int n, k;
deque<ii> coin;
int a[MAX];

void add_back(ii p){
    if(p.se == 0) return;
    if(coin.back().fi == p.fi) coin.back().se += p.se;
    else coin.pb(p);
}

void add_front(ii p){
    if(p.se == 0) return;
    if(coin.front().fi == p.fi) coin.front().se += p.se;
    else coin.push_front(p);
}

void transfer(const ii &w0, const ii &w1, int use){
    add_back(par(w0.fi - use/w0.se - 1, use%w0.se));
    add_back(par(w0.fi - use/w0.se, w0.se - use%w0.se));

    add_front(par(w1.fi + use/w1.se + 1, use%w1.se));
    add_front(par(w1.fi + use/w1.se, w1.se - use%w1.se));

    k -= use;
}

bool check(const ii &w0, const ii &w1, int limit0, int limit1, int use){
    int min0 = w0.fi - use/w0.se - (use % w0.se > 0);
    int max1 = w1.fi + use/w1.se + (use % w1.se > 0);
    if(min0 < max1 || min0 < limit0 || max1 > limit1) return false;
    return true;
}

int bfind(const ii &w0, const ii &w1, int limit0, int limit1){
    int l = 0, r = k, i = (l + r)/2;
    while(l != i && i != r){
        if(check(w0, w1, limit0, limit1, i)) l = i;
        else r = i;
        i = (l + r)/2;
    }
    for(int i = r; i >= l; i--) if(check(w0, w1, limit0, limit1, i)) return i;
    return 0;
}

void process(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    int i = 1;
    while(i <= n){
        int j = i;
        while(j < n && a[j + 1] == a[i]) j++;
        coin.pb(par(a[i], j - i + 1));
        i = j + 1;
    }

    while(k > 0 && sz(coin) > 1){
        ii bg = coin.front(); coin.pop_front();
        ii ed = coin.back(); coin.pop_back();
        int use;
        if(coin.empty()){
            use = bfind(ed, bg, 1, INF);
            transfer(ed, bg, use);
        }else{
            use = bfind(ed, bg, coin.back().fi, coin.front().fi);
            transfer(ed, bg, use);
        }
        if(use == 0) break;
    }

    if(sz(coin) == 1) cout << 0;
    else cout << coin.back().fi - coin.front().fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    //~ cin.tie(nullptr);
    //~ cout << fixed; cout.precision(10);
    //~ freopen("b.in", "r", stdin);
    process();
}


#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define sz(v) int(v.size())
#define par make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
template<class X, class Y> void amax(X& x, const Y& y){if(x < y) x = y;}
template<class X, class Y> void amin(X& x, const Y& y){if(x > y) x = y;}
typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld;
const int INF = 1e9 + 10; const ll INFL = 1e18 + 10;

int n, k;
map<int, int> cnt;
set<pair<int, int>> vv;

void add(ii p){
    if(p.se == 0) return;
    auto it = vv.lower_bound(par(p.fi, 0));
    if(it == vv.end() || it->fi != p.fi){
        vv.insert(p);
    }else{
        p.se += it->se;
        vv.erase(it);
        vv.insert(p);
    }
}

void transfer(const ii &w0, const ii &w1, int use){
    add(par(w0.fi - use/w0.se, w0.se - use%w0.se));
    add(par(w0.fi - use/w0.se - 1, use%w0.se));

    add(par(w1.fi + use/w1.se, w1.se - use%w1.se));
    add(par(w1.fi + use/w1.se + 1, use%w1.se));

    k -= use;
}

bool check(const ii &w0, const ii &w1, int limit, int use){
    int min0 = w0.fi - use/w0.se - (use % w0.se > 0);
    int max1 = w1.fi + use/w1.se + (use % w1.se > 0);
    if(min0 < max1 || max1 > limit) return false;
    return true;
}

int bfind(const ii &w0, const ii &w1, int limit){
    int l = 0, r = k, i = (l + r)/2;
    while(l != i && i != r){
        if(check(w0, w1, limit, i)) l = i;
        else r = i;
        i = (l + r)/2;
    }
    for(int i = r; i >= l; i--) if(check(w0, w1, limit, i)) return i;
    return 0;
}

void process(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int c; cin >> c;
        cnt[c]++;
    }

    for(auto p : cnt) vv.insert(p);

    while(k > 0 && sz(vv) > 1){
        ii bg = *vv.begin(); vv.erase(vv.begin());
        ii ed = *vv.rbegin(); vv.erase(prev(vv.end()));
        if(sz(vv) == 0){
            int use = bfind(ed, bg, INF);
            transfer(ed, bg, use);
            if(use == 0) break;
        }else{
            int use = bfind(ed, bg, vv.begin()->fi);
            transfer(ed, bg, use);
        }
    }

    if(sz(vv) == 1) cout << 0;
    else cout << vv.rbegin()->fi - vv.begin()->fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    //~ cin.tie(nullptr);
    //~ cout << fixed; cout.precision(10);
    //~ freopen("b.in", "r", stdin);
    process();
}


#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define sz(v) int(v.size())
#define par make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
template<class X, class Y> void amax(X& x, const Y& y){if(x < y) x = y;}
template<class X, class Y> void amin(X& x, const Y& y){if(x > y) x = y;}
typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld;
const int INF = 1e9 + 10; const ll INFL = 1e18 + 10;

int n, k;
map<int, int> cnt;
set<pair<int, int>> vv;

void add(ii p){
    if(p.se == 0) return;
    auto it = vv.lower_bound(par(p.fi, 0));
    if(it == vv.end() || it->fi != p.fi){
        vv.insert(p);
    }else{
        p.se += it->se;
        vv.erase(it);
        vv.insert(it, p);
    }
}

void transfer(const ii &w0, const ii &w1, int use){
    add(par(w0.fi - use/w0.se, w0.se - use%w0.se));
    add(par(w0.fi - use/w0.se - 1, use%w0.se));

    add(par(w1.fi + use/w1.se, w1.se - use%w1.se));
    add(par(w1.fi + use/w1.se + 1, use%w1.se));

    k -= use;
}

bool check(const ii &w0, const ii &w1, int limit0, int limit1, int use){
    int min0 = w0.fi - use/w0.se - (use % w0.se > 0);
    int max1 = w1.fi + use/w1.se + (use % w1.se > 0);
    if(min0 < max1 || min0 < limit0 || max1 > limit1) return false;
    return true;
}

int bfind(const ii &w0, const ii &w1, int limit0, int limit1){
    int l = 0, r = k, i = (l + r)/2;
    while(l != i && i != r){
        if(check(w0, w1, limit0, limit1, i)) l = i;
        else r = i;
        i = (l + r)/2;
    }
    for(int i = r; i >= l; i--) if(check(w0, w1, limit0, limit1, i)) return i;
    return 0;
}

void process(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int c; cin >> c;
        cnt[c]++;
    }

    for(auto p : cnt) vv.insert(p);

    while(k > 0 && sz(vv) > 1){
        ii bg = *vv.begin(); vv.erase(vv.begin());
        ii ed = *vv.rbegin(); vv.erase(prev(vv.end()));
        if(sz(vv) == 0){
            int use = bfind(ed, bg, 1, INF);
            transfer(ed, bg, use);
            if(use == 0) break;
        }else{
            int use = bfind(ed, bg, vv.rbegin()->fi, vv.begin()->fi);
            transfer(ed, bg, use);
        }
    }

    if(sz(vv) == 1) cout << 0;
    else cout << vv.rbegin()->fi - vv.begin()->fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    //~ cin.tie(nullptr);
    //~ cout << fixed; cout.precision(10);
    //~ freopen("b.in", "r", stdin);
    process();
}


#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define sz(v) int(v.size())
#define par make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
template<class X, class Y> void amax(X& x, const Y& y){if(x < y) x = y;}
template<class X, class Y> void amin(X& x, const Y& y){if(x > y) x = y;}
typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld;
const int INF = 1e9 + 10; const ll INFL = 1e18 + 10;

int n, k;
map<int, int> cnt;

void add(ii p){
    if(p.se == 0) return;
    if(cnt.find(p.fi) == cnt.end()){
        cnt[p.fi] = p.se;
    }else{
        cnt[p.fi] += p.se;
    }
}

void transfer(const ii &w0, const ii &w1, int use){
    add(par(w0.fi - use/w0.se, w0.se - use%w0.se));
    add(par(w0.fi - use/w0.se - 1, use%w0.se));

    add(par(w1.fi + use/w1.se, w1.se - use%w1.se));
    add(par(w1.fi + use/w1.se + 1, use%w1.se));

    k -= use;
}

bool check(const ii &w0, const ii &w1, int limit0, int limit1, int use){
    int min0 = w0.fi - use/w0.se - (use % w0.se > 0);
    int max1 = w1.fi + use/w1.se + (use % w1.se > 0);
    if(min0 < max1 || min0 < limit0 || max1 > limit1) return false;
    return true;
}

int bfind(const ii &w0, const ii &w1, int limit0, int limit1){
    int l = 0, r = k, i = (l + r)/2;
    while(l != i && i != r){
        if(check(w0, w1, limit0, limit1, i)) l = i;
        else r = i;
        i = (l + r)/2;
    }
    for(int i = r; i >= l; i--) if(check(w0, w1, limit0, limit1, i)) return i;
    return 0;
}

void process(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int c; cin >> c;
        cnt[c]++;
    }

    while(k > 0 && sz(cnt) > 1){
        ii bg = *cnt.begin(); cnt.erase(cnt.begin());
        ii ed = *cnt.rbegin(); cnt.erase(prev(cnt.end()));
        if(sz(cnt) == 0){
            int use = bfind(ed, bg, 1, INF);
            transfer(ed, bg, use);
            if(use == 0) break;
        }else{
            int use = bfind(ed, bg, cnt.rbegin()->fi, cnt.begin()->fi);
            transfer(ed, bg, use);
        }
    }

    if(sz(cnt) == 1) cout << 0;
    else cout << cnt.rbegin()->fi - cnt.begin()->fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    //~ cin.tie(nullptr);
    //~ cout << fixed; cout.precision(10);
    //~ freopen("b.in", "r", stdin);
    process();
}


#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define sz(v) int(v.size())
#define par make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
template<class X, class Y> void amax(X& x, const Y& y){if(x < y) x = y;}
template<class X, class Y> void amin(X& x, const Y& y){if(x > y) x = y;}
typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld;
const int INF = 1e9 + 10; const ll INFL = 1e18 + 10;

int n, k;
deque<ii> coin;

void add_back(ii p){
    if(p.se == 0) return;
    if(coin.back().fi == p.fi) coin.back().se += p.se;
    else coin.pb(p);
}

void add_front(ii p){
    if(p.se == 0) return;
    if(coin.front().fi == p.fi) coin.front().se += p.se;
    else coin.push_front(p);
}

void transfer(const ii &w0, const ii &w1, int use){
    add_back(par(w0.fi - use/w0.se - 1, use%w0.se));
    add_back(par(w0.fi - use/w0.se, w0.se - use%w0.se));

    add_front(par(w1.fi + use/w1.se + 1, use%w1.se));
    add_front(par(w1.fi + use/w1.se, w1.se - use%w1.se));

    k -= use;
}

bool check(const ii &w0, const ii &w1, int limit0, int limit1, int use){
    int min0 = w0.fi - use/w0.se - (use % w0.se > 0);
    int max1 = w1.fi + use/w1.se + (use % w1.se > 0);
    if(min0 < max1 || min0 < limit0 || max1 > limit1) return false;
    return true;
}

int bfind(const ii &w0, const ii &w1, int limit0, int limit1){
    int l = 0, r = k, i = (l + r)/2;
    while(l != i && i != r){
        if(check(w0, w1, limit0, limit1, i)) l = i;
        else r = i;
        i = (l + r)/2;
    }
    for(int i = r; i >= l; i--) if(check(w0, w1, limit0, limit1, i)) return i;
    return 0;
}

void process(){
    cin >> n >> k;
    map<int, int> cnt;
    for(int i = 1; i <= n; i++){
        int c; cin >> c;
        cnt[c]++;
    }
    for(auto p : cnt) coin.push_back(p);

    while(k > 0 && sz(coin) > 1){
        ii bg = coin.front(); coin.pop_front();
        ii ed = coin.back(); coin.pop_back();
        if(coin.empty()){
            int use = bfind(ed, bg, 1, INF);
            transfer(ed, bg, use);
            if(use == 0) break;
        }else{
            int use = bfind(ed, bg, coin.back().fi, coin.front().fi);
            transfer(ed, bg, use);
        }
    }

    if(sz(cnt) == 1) cout << 0;
    else cout << coin.back().fi - coin.front().fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    //~ cin.tie(nullptr);
    //~ cout << fixed; cout.precision(10);
    //~ freopen("b.in", "r", stdin);
    process();
}


#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define sz(v) int(v.size())
#define par make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
template<class X, class Y> void amax(X& x, const Y& y){if(x < y) x = y;}
template<class X, class Y> void amin(X& x, const Y& y){if(x > y) x = y;}
typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld;
const int INF = 1e9 + 10; const ll INFL = 1e18 + 10;

int n, k;
deque<ii> coin;

void add_back(ii p){
    if(p.se == 0) return;
    if(coin.back().fi == p.fi) coin.back().se += p.se;
    else coin.pb(p);
}

void add_front(ii p){
    if(p.se == 0) return;
    if(coin.front().fi == p.fi) coin.front().se += p.se;
    else coin.push_front(p);
}

void transfer(const ii &w0, const ii &w1, int use){
    add_back(par(w0.fi - use/w0.se - 1, use%w0.se));
    add_back(par(w0.fi - use/w0.se, w0.se - use%w0.se));

    add_front(par(w1.fi + use/w1.se + 1, use%w1.se));
    add_front(par(w1.fi + use/w1.se, w1.se - use%w1.se));

    k -= use;
}

bool check(const ii &w0, const ii &w1, int limit0, int limit1, int use){
    int min0 = w0.fi - use/w0.se - (use % w0.se > 0);
    int max1 = w1.fi + use/w1.se + (use % w1.se > 0);
    if(min0 < max1 || min0 < limit0 || max1 > limit1) return false;
    return true;
}

int bfind(const ii &w0, const ii &w1, int limit0, int limit1){
    int l = 0, r = k, i = (l + r)/2;
    while(l != i && i != r){
        if(check(w0, w1, limit0, limit1, i)) l = i;
        else r = i;
        i = (l + r)/2;
    }
    for(int i = r; i >= l; i--) if(check(w0, w1, limit0, limit1, i)) return i;
    return 0;
}

void process(){
    cin >> n >> k;
    map<int, int> cnt;
    for(int i = 1; i <= n; i++){
        int c; cin >> c;
        cnt[c]++;
    }
    for(auto p : cnt) coin.push_back(p);

    while(k > 0 && sz(coin) > 1){
        ii bg = coin.front(); coin.pop_front();
        ii ed = coin.back(); coin.pop_back();
        int use;
        if(coin.empty()){
            use = bfind(ed, bg, 1, INF);
            transfer(ed, bg, use);
        }else{
            use = bfind(ed, bg, coin.back().fi, coin.front().fi);
            transfer(ed, bg, use);
        }
        if(use == 0) break;
    }

    if(sz(cnt) == 1) cout << 0;
    else cout << coin.back().fi - coin.front().fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    //~ cin.tie(nullptr);
    //~ cout << fixed; cout.precision(10);
    //~ freopen("b.in", "r", stdin);
    process();
}


#include<bits/stdc++.h>
using namespace std;
const long long MX=(1<<19);
typedef long long ll;
long long n , K;
long long arr[MX];
bool check(long long X){
    ll fakss = 0;
    for(long long j=1;j<=n;j++){
        if(arr[j] < X) fakss += X - arr[j];
    }
    return fakss <= K;
}
int main(){
    scanf("%lld %lld",&n,&K);
    ll sum = 0;
    for(long long j=1;j<=n;j++) {
        scanf("%lld",&arr[j]);
        sum += arr[j];
    }
    ll st = 1 , en = *max_element(arr+1 , arr+1+n) , mid , best;
    while(st <= en){
        mid = (st+en)/2;
        if(check(mid)){
            st = mid+1;
            best = mid;
        }
        else en = mid-1;
    }
    sort(arr+1 , arr+1+n);
    reverse(arr+1 , arr+1+n);
    //cout<<best<<endl;
    for(long long j = 1 ; j <= n ;){
        long long i = j;
        if(arr[j] == best){
            if(sum%n) puts("1");
            else puts("0");
            return 0;
        }
        while(i+1 <= n && arr[i+1] == arr[j]) ++i;
        long long cur = i;
        ll dif = arr[j] - arr[j+1];
        ll theta = dif * cur;
        if(theta <= K){
            K-= theta;
            j = i+1;
            continue;
        }
        K/=cur;
        cout<<arr[j] - K - best<<endl;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long MX=(1<<19);
typedef long long ll;
long long n , K;
long long arr[MX];
bool check(long long X){
    ll fakss = 0;
    for(long long j=1;j<=n;j++){
        if(arr[j] < X) fakss += X - arr[j];
    }
    return fakss <= K;
}
int main(){
    scanf("%lld %lld",&n,&K);
    ll sum = 0;
    for(long long j=1;j<=n;j++) {
        scanf("%lld",&arr[j]);
        sum += arr[j];
    }
    ll st = 1 , en = *max_element(arr+1 , arr+1+n) , mid , best;
    while(st <= en){
        mid = (st+en)/2;
        if(check(mid)){
            st = mid+1;
            best = mid;
        }
        else en = mid-1;
    }
    sort(arr+1 , arr+1+n);
    reverse(arr+1 , arr+1+n);
    //cout<<best<<endl;
    for(long long j = 1 ; j <= n ;){
        long long i = j;
        if(arr[j] == best){
            if(sum%n) puts("1");
            else puts("0");
            return 0;
        }
        while(i+1 <= n && arr[i+1] == arr[j]) ++i;
        long long cur = i;
        ll dif = arr[i] - arr[i+1];
        ll theta = dif * cur;
        if(theta < K){
            K-= theta;
            j = i+1;
            continue;
        }
        //cout<<j<<' '<<arr[j]<<' '<<K<<endl;
        K/=cur;
        cout<<arr[j] - K - best<<endl;
        return 0;
    }
    if(sum%n) puts("1");
    else puts("0");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long MX=(1<<19);
typedef long long ll;
long long n , K;
long long arr[MX];
bool check(long long X){
    ll fakss = 0;
    for(long long j=1;j<=n;j++){
        if(arr[j] < X) fakss += X - arr[j];
    }
    return fakss <= K;
}
int main(){
    scanf("%lld %lld",&n,&K);
    ll sum = 0;
    for(long long j=1;j<=n;j++) {
        scanf("%lld",&arr[j]);
        sum += arr[j];
    }
    ll st = 1 , en = *max_element(arr+1 , arr+1+n) , mid , best;
    while(st <= en){
        mid = (st+en)/2;
        if(check(mid)){
            st = mid+1;
            best = mid;
        }
        else en = mid-1;
    }
    sort(arr+1 , arr+1+n);
    reverse(arr+1 , arr+1+n);
    //cout<<best<<endl;
    for(long long j = 1 ; j <= n ;){
        long long i = j;
        if(arr[j] == best){
            if(sum%n) puts("1");
            else puts("0");
            return 0;
        }
        while(i+1 <= n && arr[i+1] == arr[j]) ++i;
        long long cur = i;
        ll dif = arr[i] - arr[i+1];
        ll theta = dif * cur;
        if(theta <= K){
            K-= theta;
            j = i+1;
            continue;
        }
        //cout<<j<<' '<<arr[j]<<' '<<K<<endl;
        K/=cur;
        cout<<arr[j] - K - best<<endl;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long MX=(1<<19);
typedef long long ll;
long long n , K;
long long arr[MX];
bool check(long long X){
    ll fakss = 0;
    for(long long j=1;j<=n;j++){
        if(arr[j] < X) fakss += X - arr[j];
    }
    return fakss <= K;
}
int main(){
    scanf("%lld %lld",&n,&K);
    ll sum = 0;
    for(long long j=1;j<=n;j++) {
        scanf("%lld",&arr[j]);
        sum += arr[j];
    }
    ll st = 1 , en = *max_element(arr+1 , arr+1+n) , mid , best;
    while(st <= en){
        mid = (st+en)/2;
        if(check(mid)){
            st = mid+1;
            best = mid;
        }
        else en = mid-1;
    }
    sort(arr+1 , arr+1+n);
    reverse(arr+1 , arr+1+n);
    //cout<<best<<endl;
    for(long long j = 1 ; j <= n ;){
        long long i = j;
        if(arr[j] == best){
            if(sum%n) puts("1");
            else puts("0");
            return 0;
        }
        while(i+1 <= n && arr[i+1] == arr[j]) ++i;
        long long cur = i;
        ll dif = arr[i] - arr[i+1];
        ll theta = dif * cur;
        if(theta <= K){
            K-= theta;
            j = i+1;
            continue;
        }
        //cout<<j<<' '<<arr[j]<<' '<<K<<endl;
        K/=cur;
        cout<<arr[j] - K - best<<endl;
        return 0;
    }
    if(sum%n) puts("1");
    else puts("0");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long MX=(1<<19);
typedef long long ll;
long long n , K;
long long arr[MX];
bool check(long long X){
    ll fakss = 0;
    for(long long j=1;j<=n;j++){
        if(arr[j] < X) fakss += X - arr[j];
    }
    return fakss <= K;
}
int main(){
    scanf("%lld %lld",&n,&K);
    ll sum = 0;
    for(long long j=1;j<=n;j++) {
        scanf("%lld",&arr[j]);
        sum += arr[j];
    }
    ll st = 1 , en = *max_element(arr+1 , arr+1+n) , mid , best;
    while(st <= en){
        mid = (st+en)/2;
        if(check(mid)){
            st = mid+1;
            best = mid;
        }
        else en = mid-1;
    }
    sort(arr+1 , arr+1+n);
    reverse(arr+1 , arr+1+n);
    //cout<<best<<endl;
    for(long long j = 1 ; j <= n ;){
        long long i = j;
        if(arr[j] == best){
            if(sum%n) puts("1");
            else puts("0");
            return 0;
        }
        while(i+1 <= n && arr[i+1] == arr[j]) ++i;
        long long cur = i;
        ll dif = arr[j] - arr[j+1];
        ll theta = dif * cur;
        if(theta <= K){
            K-= theta;
            j = i+1;
            continue;
        }
        K/=cur;
        //cout<<arr[j] - K - best<<endl;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MX=(1<<19);
typedef long long ll;
int n , K;
int arr[MX];
bool check(int X){
    ll fakss = 0;
    for(int j=1;j<=n;j++){
        if(arr[j] < X) fakss += X - arr[j];
    }
    return fakss <= K;
}
int main(){
    scanf("%d %d",&n,&K);
    ll sum = 0;
    for(int j=1;j<=n;j++) {
        scanf("%d",&arr[j]);
        sum += arr[j];
    }
    ll st = 1 , en = *max_element(arr+1 , arr+1+n) , mid , best;
    while(st <= en){
        mid = (st+en)/2;
        if(check(mid)){
            st = mid+1;
            best = mid;
        }
        else en = mid-1;
    }
    sort(arr+1 , arr+1+n);
    reverse(arr+1 , arr+1+n);
    cout<<best<<endl;
    for(int j = 1 ; j <= n ;){
        int i = j;
        if(arr[j] == best){
            if(sum%n) puts("1");
            else puts("0");
            return 0;
        }
        while(i+1 <= n && arr[i+1] == arr[j]) ++i;
        int cur = i;
        ll dif = arr[j] - arr[j+1];
        ll theta = dif * cur;
        if(theta <= K){
            K-= theta;
            j = i+1;
            continue;
        }
        K/=cur;
        //cout<<arr[j] - K - best<<endl;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long MX=(1<<19);
typedef long long ll;
long long n , K;
long long arr[MX];
bool check(long long X){
    ll fakss = 0;
    for(long long j=1;j<=n;j++){
        if(arr[j] < X) fakss += X - arr[j];
    }
    return fakss <= K;
}
int main(){
    scanf("%lld %lld",&n,&K);
    ll sum = 0;
    for(long long j=1;j<=n;j++) {
        scanf("%lld",&arr[j]);
        sum += arr[j];
    }
    ll st = 1 , en = *max_element(arr+1 , arr+1+n) , mid , best;
    while(st <= en){
        mid = (st+en)/2;
        if(check(mid)){
            st = mid+1;
            best = mid;
        }
        else en = mid-1;
    }
    sort(arr+1 , arr+1+n);
    reverse(arr+1 , arr+1+n);
    //cout<<best<<endl;
    for(long long j = 1 ; j <= n ;){
        long long i = j;
        if(arr[j] <= best){
            if(sum%n) puts("1");
            else puts("0");
            return 0;
        }
        while(i+1 <= n && arr[i+1] == arr[j]) ++i;
        long long cur = i;
        ll dif = arr[i] - max( best , arr[i+1] );
        ll theta = dif * cur;
        if(theta <= K){
            K-= theta;
            j = i+1;
            continue;
        }
        //cout<<j<<' '<<arr[j]<<' '<<K<<endl;
        K/=cur;
        cout<<arr[j] - K - best<<endl;
        return 0;
    }
    if(sum%n) puts("1");
    else puts("0");
    return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;

void solve() {
	int n, k;
	cin >> n >> k;

	i64 Sum = 0;
	vector<int> arr(n);
	for (int a = 0; a < n; a++) {
		cin >> arr[a];
		Sum += arr[a];
	}

	sort(all(arr));

	// for (int a = 0; a < n; a++)
		// cerr << arr[a] << ' ';

	int k1 = k;
	int Max = arr.back();
	while (k1 > 0) {
		auto low = lower_bound(all(arr), Max);

		auto wid = arr.end() - low;
		auto hgh = Max - arr[(low - arr.begin()) - 1];
		k1 -= (wid * hgh);

		if (k1 < 0) {
			k1 += (wid * hgh);
			Max -= floor(1.0 * k1 / wid);
			break;
		}

		Max -= hgh;
	}

	if (Max < ceil(1.0 * Sum / n))
		Max = ceil(1.0 * Sum / n);

	int k2 = k;
	int Min = arr.front();
	while (k2 > 0) {
		auto up = upper_bound(all(arr), Min);

		auto wid = up - arr.begin();
		auto hgh = arr[up - arr.begin()] - Min;
		k2 -= (wid * hgh);

		if (k2 < 0) {
			k2 += (wid * hgh);
			Min += floor(1.0 * k2 / wid);
			break;
		}

		Min += hgh;
	}
	// cerr << Min;

	if (Min > floor(1.0 * Sum / n))
		Min = floor(1.0 * Sum / n);

	cout << Max - Min;
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;

void solve() {
	int n, k;
	cin >> n >> k;

	i64 Sum = 0;
	vector<int> arr(n);
	for (int a = 0; a < n; a++) {
		cin >> arr[a];
		Sum += arr[a];
	}

	sort(all(arr));

	// for (int a = 0; a < n; a++)
		// cerr << arr[a] << ' ';

	int k1 = k;
	int Max = arr.back();
	while (k1 > 0) {
		auto low = lower_bound(all(arr), Max);

		auto wid = arr.end() - low;
		auto hgh = Max - arr[(low - arr.begin()) - 1];
		k1 -= (wid * hgh);

		if (k1 < 0) {
			k1 += (wid * hgh);
			Max -= floor(1.0 * k1 / wid);
			break;
		}

		if (Max <= ceil(1.0 * Sum / n)) {
			Max = ceil(1.0 * Sum / n);
			break;
		}

		Max -= hgh;
	}

	int k2 = k;
	int Min = arr.front();
	while (k2 > 0) {
		auto up = upper_bound(all(arr), Min);

		auto wid = up - arr.begin();
		auto hgh = arr[up - arr.begin()] - Min;
		k2 -= (wid * hgh);

		if (k2 < 0) {
			k2 += (wid * hgh);
			Min += floor(1.0 * k2 / wid);
			break;
		}

		if (Min >= floor(1.0 * Sum / n)) {
			Min = floor(1.0 * Sum / n);
			break;
		}

		Min += hgh;
	}
	// cerr << Min;

	cout << Max - Min;
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;

void solve() {
	int n, k;
	cin >> n >> k;

	i64 Sum = 0;
	vector<int> arr(n);
	for (int a = 0; a < n; a++) {
		cin >> arr[a];
		Sum += arr[a];
	}

	sort(all(arr));

	// for (int a = 0; a < n; a++)
		// cerr << arr[a] << ' ';

	i64 k1 = k;
	int Max = arr.back();
	while (k1 > 0) {
		auto low = lower_bound(all(arr), Max);

		auto wid = arr.end() - low;
		if (wid == n) {
			Max = 0;
			break;
		}

		auto hgh = Max - arr[(low - arr.begin()) - 1];
		k1 -= ((i64)wid * hgh);

		if (k1 < 0) {
			k1 += ((i64)wid * hgh);
			Max -= floor(1.0 * k1 / wid);
			break;
		}

		if (Max <= ceil(1.0 * Sum / n)) {
			Max = ceil(1.0 * Sum / n);
			break;
		}

		Max -= hgh;
	}

	i64 k2 = k;
	int Min = arr.front();
	while (k2 > 0) {
		auto up = upper_bound(all(arr), Min);

		auto wid = up - arr.begin();
		if (wid == n) {
			Min = 0;
			break;
		}

		auto hgh = arr[up - arr.begin()] - Min; //cerr << hgh;
		k2 -= ((i64)wid * hgh);

		if (k2 < 0) {
			k2 += ((i64)wid * hgh);
			Min += floor(1.0 * k2 / wid);
			break;
		}

		if (Min >= floor(1.0 * Sum / n)) {
			Min = floor(1.0 * Sum / n);
			break;
		}

		Min += hgh;
	}
	// cerr << Min;

	cout << Max - Min;
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;

void solve() {
	int n, k;
	cin >> n >> k;

	i64 Sum = 0;
	vector<int> arr(n);
	for (int a = 0; a < n; a++) {
		cin >> arr[a];
		Sum += arr[a];
	}

	sort(all(arr));

	// for (int a = 0; a < n; a++)
		// cerr << arr[a] << ' ';

	int k1 = k;
	int Max = arr.back();
	while (k1 > 0) {
		auto low = lower_bound(all(arr), Max);

		auto wid = arr.end() - low;
		if (wid == n) {
			Max = 0;
			break;
		}

		auto hgh = Max - arr[(low - arr.begin()) - 1];
		k1 -= (wid * hgh);

		if (k1 < 0) {
			k1 += (wid * hgh);
			Max -= floor(1.0 * k1 / wid);
			break;
		}

		if (Max <= ceil(1.0 * Sum / n)) {
			Max = ceil(1.0 * Sum / n);
			break;
		}

		Max -= hgh;
	}

	int k2 = k;
	int Min = arr.front();
	while (k2 > 0) {
		auto up = upper_bound(all(arr), Min);

		auto wid = up - arr.begin();
		if (wid == n) {
			Min = 0;
			break;
		}

		auto hgh = arr[up - arr.begin()] - Min;
		k2 -= (wid * hgh);

		if (k2 < 0) {
			k2 += (wid * hgh);
			Min += floor(1.0 * k2 / wid);
			break;
		}

		if (Min >= floor(1.0 * Sum / n)) {
			Min = floor(1.0 * Sum / n);
			break;
		}

		Min += hgh;
	}
	// cerr << Min;

	cout << Max - Min;
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;

void solve() {
	int n, k;
	cin >> n >> k;

	i64 Sum = 0;
	vector<int> arr(n);
	for (int a = 0; a < n; a++) {
		cin >> arr[a];
		Sum += arr[a];
	}

	sort(all(arr));

	// for (int a = 0; a < n; a++)
		// cerr << arr[a] << ' ';

	i64 k1 = k;
	int Max = arr.back();
	while (k1 > 0) {
		auto low = lower_bound(all(arr), Max);

		auto wid = arr.end() - low;
		if (wid == n) {
			Max = 0;
			break;
		}

		auto hgh = Max - arr[(low - arr.begin()) - 1];
		k1 -= ((i64)wid * hgh);

		bool Out = 0;
		if (k1 < 0) {
			k1 += ((i64)wid * hgh);
			Max -= floor(1.0 * k1 / wid);
			Out = 1;
		}
		// cerr << Max << ' ';
		if (Max <= ceil(1.0 * Sum / n)) {
			Max = ceil(1.0 * Sum / n); //cerr << 'j';
			Out = 1;
		}

		if (Out)
			break;

		Max -= hgh;
		if (Max <= ceil(1.0 * Sum / n)) {
			Max = ceil(1.0 * Sum / n); //cerr << 'j';
			break;
		}
	}
	// cerr << Max;

	i64 k2 = k;
	int Min = arr.front();
	while (k2 > 0) {
		auto up = upper_bound(all(arr), Min);

		auto wid = up - arr.begin();
		if (wid == n) {
			Min = 0;
			break;
		}

		auto hgh = arr[up - arr.begin()] - Min; //cerr << hgh;
		k2 -= ((i64)wid * hgh);

		bool Out = 0;
		if (k2 < 0) {
			k2 += ((i64)wid * hgh);
			Min += floor(1.0 * k2 / wid);
			Out = 1;
		}

		if (Min >= floor(1.0 * Sum / n)) {
			Min = floor(1.0 * Sum / n);
			Out = 1;
		}

		if (Out)
			break;

		Min += hgh; //cerr << Min << ' ';
		if (Min >= floor(1.0 * Sum / n)) {
			Min = floor(1.0 * Sum / n);
			break;
		}
	}

	// cout << Max << ' ' << Min;
	cout << Max - Min;
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;

void solve() {
	int n, k;
	cin >> n >> k;

	i64 Sum = 0;
	vector<int> arr(n);
	for (int a = 0; a < n; a++) {
		cin >> arr[a];
		Sum += arr[a];
	}

	sort(all(arr));

	int Max = arr.back();
	while (k > 0) {
		auto low = lower_bound(all(arr), Max);

		auto wid = arr.end() - low;
		auto hgh = Max - arr[(low - arr.begin()) - 1];
		k -= (wid * hgh);

		if (k < 0) {
			k += (wid * hgh);
			Max -= floor(1.0 * k / wid);
			break;
		}

		Max -= hgh;
	}

	if (Max < ceil(1.0 * Sum / n))
		Max = ceil(1.0 * Sum / n);

	int Min = arr.front();
	while (k > 0) {
		auto up = upper_bound(all(arr), Min);

		auto wid = up - arr.begin();
		auto hgh = arr[up - arr.begin()] - Min;
		k -= (wid * hgh);

		if (k < 0) {
			k += (wid * hgh);
			Min += floor(1.0 * k / wid);
			break;
		}

		Min += hgh;
	}

	if (Min > floor(1.0 * Sum / n))
		Min = floor(1.0 * Sum / n);

	cout << Max - Min;
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;
const int MX = 1e5 + 5;

void bit_func(int val) {
	// while (val--) {
		cerr << val << ' ';

		vector<bool> bit;
		while (val > 0) {
			bit.pb(val % 2);
			val /= 2;
		}
		reverse(all(bit));

		for (int a = 0; a < (int)bit.size(); a++)
			if (bit[a])
				cerr << 'O' << ' ';
			else
				cerr << '.' << ' ';

		cerr << '\n';
	// }
}

bool prime(int val) {
	if (val == 2 || val == 3 || val == 5 || val == 7)
		return true;
	if (val % 2 == 0 || val < 11)
		return false;

	for (int a = 3; a * a <= val; a += 2)
		if (val % a == 0)
			return false;

	return true;
}

void solve() {
	for (int a = 2; a < 100; a++)
		// if (prime(a))
			bit_func(a);
			// cerr << a << ' ';
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;

void solve() {
	int n, k;
	cin >> n >> k;

	i64 Sum = 0;
	vector<int> arr(n);
	for (int a = 0; a < n; a++) {
		cin >> arr[a];
		Sum += arr[a];
	}

	sort(all(arr));

	// for (int a = 0; a < n; a++)
		// cerr << arr[a] << ' ';

	i64 k1 = k;
	int Max = arr.back();
	while (k1 > 0) {
		auto low = lower_bound(all(arr), Max);

		auto wid = arr.end() - low;
		if (wid == n) {
			Max = 0;
			break;
		}

		auto hgh = Max - arr[(low - arr.begin()) - 1];
		k1 -= ((i64)wid * hgh);

		bool Out = 0;
		if (k1 < 0) {
			k1 += ((i64)wid * hgh);
			Max -= floor(1.0 * k1 / wid);
			Out = 1;
		}

		if (Max <= ceil(1.0 * Sum / n)) {
			Max = ceil(1.0 * Sum / n); //cerr << 'j';
			Out = 1;
		}

		if (Out)
			break;

		Max -= hgh; //cerr << Max << ' ';
	}
	// cerr << Max;

	i64 k2 = k;
	int Min = arr.front();
	while (k2 > 0) {
		auto up = upper_bound(all(arr), Min);

		auto wid = up - arr.begin();
		if (wid == n) {
			Min = 0;
			break;
		}

		auto hgh = arr[up - arr.begin()] - Min; //cerr << hgh;
		k2 -= ((i64)wid * hgh);

		bool Out = 0;
		if (k2 < 0) {
			k2 += ((i64)wid * hgh);
			Min += floor(1.0 * k2 / wid);
			Out = 1;
		}

		if (Min >= floor(1.0 * Sum / n)) {
			Min = floor(1.0 * Sum / n);
			Out = 1;
		}

		if (Out)
			break;

		Min += hgh;
	}
	// cerr << Min;

	cout << Max - Min;
}

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

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;
ll b[500005];
int n,k;
ll sum;
bool cmp (ll x,ll y){
    return x > y;
}

int main() {
    scanf("%d%d",&n,&k);
    sum = 0;
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&b[i]);
        sum += b[i];
    }
    sort(b,b+n,cmp);
    if(b[0] == b[n-1]){
        printf("0\n");
        return 0;
    }
    while(k--){
        int tol = b[0]-1;
        int k = b[n-1]+1;
        if(tol <= k){
            break;
        }else{
            b[0] = 0;
            b[n-1] = k;
        }
        sort(b,b+n,cmp);
    }
   printf("%I64d\n",b[0]-b[n-1]);
    return  0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;

ll b[500005];
int n,k;
bool cmp (ll x,ll y) {
    return x >= y;
}

int ok(int mx) {
    ll kk = 0,tt = 0;
    for(int i = 0; i < n; i++) {
        if(b[i] > mx) {
            kk += (b[i]-mx);
        } else {
            tt += (mx-b[i]);
        }
    }
    if(kk <= k && tt >= kk) return 1;
    return 0;
}
int ok2(int mi) {
    ll kk = 0,tt = 0;
    for(int i = 0; i < n; i++) {
        if(b[i] < mi) {
            kk += (mi-b[i]);
        } else {
            tt += (b[i]-mi);
        }
    }
    if(kk <= k && tt >= kk) return 1;
    return 0;
}

int main() {
    scanf("%d%d",&n,&k);
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&b[i]);
    }
    sort(b,b+n,cmp);
    int mx = b[0],mi = b[n-1];
    int r = mx,l = mi;
    while(l<= r) {
        int mid = (l+r)/2;
        if(ok(mid)) {
            r = mid-1;
            mx = mid;
        } else {
            l = mid+1;
        }
    }
    r = b[0];
    l = b[n-1];
    while(l<= r) {
        int mid = (l+r)/2;
        if(ok2(mid)) {
            l = mid+1;
            mi = mid;
        } else {
            r = mid-1;
        }
    }
    cout << mx-mi << endl;
    return  0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;

ll b[500005];
int n,k;

int ok(int mx) {
    ll kk = 0,tt = 0;
    for(int i = 0; i < n; i++) {
        if(b[i] > mx) {
            kk += (b[i]-mx);
        } else {
            tt += (mx-b[i]);
        }
    }
    if(kk <= k && tt >= kk) return 1;
    return 0;
}
int ok2(int mi) {
    ll kk = 0,tt = 0;
    for(int i = 0; i < n; i++) {
        if(b[i] < mi) {
            kk += (mi-b[i]);
        } else {
            tt += (b[i]-mi);
        }
    }
    if(kk <= k && tt >= kk) return 1;
    return 0;
}

int main() {
    scanf("%d%d",&n,&k);
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&b[i]);
    }
    sort(b,b+n);
    int mx = b[n-1],mi = b[0];
    int r = mx,l = mi;
    while(l<= r) {
        int mid = (l+r)/2;
        if(ok(mid)) {
            r = mid-1;
            mx = mid;
        } else {
            l = mid+1;
        }
    }
    r = b[n-1];
    l = b[0];
    while(l<= r) {
        int mid = (l+r)/2;
        if(ok2(mid)) {
            l = mid+1;
            mi = mid;
        } else {
            r = mid-1;
        }
    }
    printf("%d\n",mx-mi);
    return  0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;
ll b[1000000];
int n,k;
ll sum;
bool cmp (ll x,ll y){
    return x > y;
}

int main() {
    scanf("%d%d",&n,&k);
    sum = 0;
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&b[i]);
        sum += b[i];
    }
    sort(b,b+n,cmp);
    if(b[0] == b[n-1]){
        printf("0\n");
        return 0;
    }
    int ave = sum/n;
    sum = 0;
    int i = 0;
    while(sum < k){
       if(sum + (b[i]-ave) < k){
         i++;
         b[i] = ave;
       }else{
           b[i] -= (k-sum);
           sum = k;
       }
    }
    for(int j = n-1;j>=0 && sum;j--){
        if(b[j]+sum <= ave){
            b[j] = b[j]+sum;
            sum = 0;
        }else{
            b[j] = ave;
            sum -= ave;
        }
    }
   sort(b,b+n);
   printf("%I64d\n",b[n-1]-b[0]);
    return  0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e6+20, M = 1e7, mod = 1e9+7,inf  = 1e9+7;
typedef long long ll;

int a[N],n,k;
int check1(int mx) {
    ll kk = 0,buji = 0;
    for(int i=1;i<=n;i++) {
        if(a[i]>mx) kk+=(a[i]-mx);
        else {
            buji+=(mx - a[i]);
        }
    }
    if(kk<=k&&buji>=kk) return 1;
    else return 0;
}
int check2(int mi) {
    ll kk = 0,buji = 0;
    for(int i=1;i<=n;i++) {
        if(a[i]<mi) kk+=(mi - a[i]);
        else buji += (a[i] - mi);
    }
    if(kk<=k&&buji>=kk) return 1;
    else
    return 0;
}
int main() {
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int mx = a[n],mi = a[1];
    int r = a[n], l = a[1];
    while(l<=r) {
        int mid = (l+r)>>1;
        if(check1(mid))  r = mid-1,mx = mid;
        else l = mid+1;
    }
    r = a[n], l = a[1];
    while(l<=r) {
        int mid = (l+r)>>1;
        if(check2(mid))  l = mid+1, mi = mid;
        else r = mid-1;
    }
    //cout<<mx<<" "<<mi<<endl;
    cout<<mx - mi<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;
ll b[500005];
int n,k;
ll sum;
bool cmp (ll x,ll y){
    return x > y;
}

int main() {
    scanf("%d%d",&n,&k);
    sum = 0;
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&b[i]);
        sum += b[i];
    }
    sort(b,b+n,cmp);
    if(b[0] == b[n-1]){
        printf("0\n");
        return 0;
    }
    while(k--){
        int tol = b[0]-1;
        int gg = b[n-1]+1;
        if(tol < gg){
            break;
        }else{
            b[0] = tol;
            b[n-1] = gg;
        }
        sort(b,b+n,cmp);
    }
   printf("%I64d\n",b[0]-b[n-1]);
    return  0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;
ll b[500005];
int n,k;
ll sum;
bool cmp (ll x,ll y){
    return x > y;
}

int main() {
    scanf("%d%d",&n,&k);
    sum = 0;
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&b[i]);
        sum += b[i];
    }
    sort(b,b+n,cmp);
    if(b[0] == b[n-1]){
        printf("0\n");
        return 0;
    }
    while(k--){
        int tol = b[0]-1;
        int k = b[n-1]+1;
        if(tol <= k){
            break;
        }else{
            b[0] = tol;
            b[n-1] = k;
        }
        sort(b,b+n,cmp);
    }
   printf("%I64d\n",b[0]-b[n-1]);
    return  0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;
ll b[500005];
int n,k;
ll sum;
bool cmp (ll x,ll y){
    return x > y;
}

int main() {
    scanf("%d%d",&n,&k);
    sum = 0;
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&b[i]);
        sum += b[i];
    }
    sort(b,b+n,cmp);
    if(b[0] == b[n-1]){
        printf("0\n");
        return 0;
    }
    int ave = sum/n;
    sum = 0;
    int i = 0;
    while(sum < k){
       if(sum + (b[i]-ave) < k){
         i++;
         b[i] = ave;
       }else{
           b[i] -= (k-sum);
           sum = k;
       }
    }
    for(int j = n-1;j>=0 && sum;j--){
        if(b[j]+sum <= ave){
            b[j] = b[j]+sum;
            sum = 0;
        }else{
            b[j] = ave;
            sum -= ave;
        }
    }
   sort(b,b+n);
   printf("%I64d\n",b[n-1]-b[0]);
    return  0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

map<ll,ll> have;

int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        have[arr[i]]++;
    }
    sort(arr,arr+n);
    ll num,ind=-1;
    for(int i=0; i<n-1; i++)
    {
        if(arr[i+1]-arr[i]>1)
        {
            ind=i;
            num=arr[i]+1;
            break;
        }
    }
    if(arr[0]!=1)
    {
        num=1;
      ind=1;
    }
    for(int i=0; i<n; i++)
    {
        while(have[arr[i]] && arr[i]>num)
        {
            num++;
            have[arr[i]]--;
        }
        if(have[arr[i]] && arr[i]==num)
            num++;
    }
    if(ind==-1)
        cout<<arr[n-1]+1;
    else
        cout<<num<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

map<int,int> check,have;

int main()
{
    ll n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        have[arr[i]]++;;
    }
    sort(arr,arr+n);
    ll num,ind=-1;
    for(int i=0; i<n-1; i++)
    {
        if(arr[i+1]-arr[i]>1)
        {
            ind=i;
            num=arr[i]+1;
            break;
        }
    }
    for(int i=0; i<n; i++)
    {
        if(have[arr[i]] && arr[i]>num)
        {
            while(have[arr[i]] && arr[i]>=num)
            {
                num++;
                have[arr[i]]--;
            }
        }
    }
    if(ind==-1)
        cout<<arr[n-1]+1;
    else
        cout<<num<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

map<int,int> check,have;

int main()
{
    ll n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        have[arr[i]]++;;
    }
    sort(arr,arr+n);
    ll num,ind=-1;
    for(int i=0; i<n-1; i++)
    {
        if(arr[i+1]-arr[i]>1)
        {
            ind=i;
            num=arr[i]+1;
            break;
        }
    }
    for(int i=0; i<n; i++)
    {
        if(have[arr[i]] && arr[i]>=num)
        {
            num++;
            have[arr[i]]--;
            while(have[num])
            {
                num++;
            }
        }
    }
    if(ind==-1)
        cout<<arr[n-1]+1;
    else
    cout<<num<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

#define MAX 1e7+5
#define PI 3.141592653589793238462643383279502884197169399
#define forn(i,s,n) for(int i=s;i<n;i++)
#define fornr(i,s,n) for(int i=n ; i>s;i--)
typedef  long long ll;
using namespace std;

int main() {
     int n , arr[123456] , ans=0;
     map< ll , bool > mp;

     cin >> n;
     forn(i , 0 , n)cin >> arr[i];

    mp[arr[0]]=1;
     forn(i , 1 , n){
          if(arr[i]-arr[i-1] >1)arr[i]=arr[i-1]+1;
          mp[arr[i]]=1;

     }

     forn(i , 1 , n+2)if(!mp[i]){ans=i; break;}
     if(n==1)ans=2;
     cout << ans;
}


#include <bits/stdc++.h>
#define MOD 1000000007

#define MAX 1e7+5
#define PI 3.141592653589793238462643383279502884197169399
#define forn(i,s,n) for(int i=s;i<n;i++)
#define fornr(i,s,n) for(int i=n ; i>s;i--)
typedef  long long ll;
using namespace std;

int main() {
     int n , arr[123456] , ans=0,cnt[1234567];
     map< ll , bool > mp;

     cin >> n;
     forn(i , 1 , n+1)cin >> arr[i];
     sort(arr+1, arr+n+1);

    arr[0]=1;
     forn(i , 1 , n+1){
          if(arr[i]-arr[i-1] >1)arr[i]=arr[i-1]+1;
          mp[arr[i]]=1;

     }

     forn(i , 1 , n+2)if(!mp[i]){ans=i; break;}
     if(n==1)ans=2;
     cout << ans;
}


#include <bits/stdc++.h>
#define MOD 1000000007

#define MAX 1e7+5
#define PI 3.141592653589793238462643383279502884197169399
#define forn(i,s,n) for(int i=s;i<n;i++)
#define fornr(i,s,n) for(int i=n ; i>s;i--)
typedef  long long ll;
using namespace std;

int main() {
     int n , arr[123456] , ans=0;
     bool x[123456];
     memset( x , 0 , sizeof x);
     cin >> n;
     forn(i , 1 , n+1)cin >> arr[i];
     arr[0]=0;
     forn(i , 1 , n+1){
          if(arr[i]-arr[i-1] >1)arr[i]=arr[i-1]+1;
          x[arr[i]]=1;

     }
     forn(i , 1 , n+2)if(!x[i]){ans=i; break;}
     cout << ans;
}


#include <bits/stdc++.h>
#define MOD 1000000007

#define MAX 1e7+5
#define PI 3.141592653589793238462643383279502884197169399
#define forn(i,s,n) for(int i=s;i<n;i++)
#define fornr(i,s,n) for(int i=n ; i>s;i--)
typedef  long long ll;
using namespace std;

int main() {
     int n , arr[123456] , ans=0,cnt[1234567];
     map< ll , bool > mp;

     cin >> n;
     forn(i , 1 , n+1)cin >> arr[i];
     sort(arr, arr+n);

    arr[0]=1;
     forn(i , 1 , n+1){
          if(arr[i]-arr[i-1] >1)arr[i]=arr[i-1]+1;
          mp[arr[i]]=1;

     }

     forn(i , 1 , n+2)if(!mp[i]){ans=i; break;}
     if(n==1)ans=2;
     cout << ans;
}


#include <bits/stdc++.h>
#define MOD 1000000007

#define MAX 1e7+5
#define PI 3.141592653589793238462643383279502884197169399
#define forn(i,s,n) for(int i=s;i<n;i++)
#define fornr(i,s,n) for(int i=n ; i>s;i--)
typedef  long long ll;
using namespace std;

int main() {
     int n , arr[123456] , ans=0;
     bool x[123456];
     memset( x , 0 , sizeof x);
     cin >> n;
     forn(i , 0 , n)cin >> arr[i];
     x[arr[0]]=1;
     forn(i , 1 , n){
          if(arr[i]-arr[i-1] >1)arr[i]=arr[i-1]+1;
          x[arr[i]]=1;

     }

     forn(i , 1 , n+2)if(!x[i]){ans=i; break;}
     if(n==1)ans=2;
     cout << ans;
}


#include <bits/stdc++.h>
#define MOD 1000000007

#define MAX 1e7+5
#define PI 3.141592653589793238462643383279502884197169399
#define forn(i,s,n) for(int i=s;i<n;i++)
#define fornr(i,s,n) for(int i=n ; i>s;i--)
typedef  long long ll;
using namespace std;

int main() {
     int n , arr[123456] , cnt[1234567];
     map< ll , bool > mp;

     cin >> n;
     forn(i , 0 , n)cin >> arr[i];
     sort(arr, arr+n);

     ll ans=1;
     forn(i , 0 , n)if(arr[i]>=ans)ans++;
     cout << ans;
}


#include <bits/stdc++.h>
#define MOD 1000000007

#define MAX 1e7+5
#define PI 3.141592653589793238462643383279502884197169399
#define forn(i,s,n) for(int i=s;i<n;i++)
#define fornr(i,s,n) for(int i=n ; i>s;i--)
typedef  long long ll;
using namespace std;

int main() {
     int n , arr[123456] , ans=0;
     bool x[123456];
     memset( x , 0 , sizeof x);
     cin >> n;
     forn(i , 0 , n)cin >> arr[i];
     x[arr[0]]=1;
     forn(i , 1 , n){
          while(abs(arr[i]-arr[i-1]) >1)arr[i]--;
          x[arr[i]]=1;

     }
     forn(i , 1 , n+2)if(!x[i]){ans=i; break;}
     cout << ans;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}
ll smas[(ll)1e7] {};

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=0;
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>tmp){
            smas[i]=tmp+1;
            tmp++;
        }
        //cout << smas[i]  << ' ' ;
    }
    cout << tmp << endl;

    fin.close();
    fout.close();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=1;
    ll smas[(ll)1e6] {};
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>i){
            smas[i]=tmp+1;
            tmp++;
        }
        else
            tmp=smas[i];
    }
    cout << smas[n]+1;

    fin.close();
    fout.close();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}
ll smas[(ll)1e7] {};

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=0;
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>=i){
            smas[i]=tmp+1;
            tmp++;
        }
        //cout << smas[i]  << ' ' ;
    }
    cout << tmp << endl;

    fin.close();
    fout.close();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}
ll smas[(ll)1e7] {};

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=0;
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>=i){
            smas[i]=tmp+1;
            tmp++;
        }
        else
            tmp=smas[i];
        //cout << smas[i]  << ' ' ;
    }
    cout << smas[n]+1 << endl;

    fin.close();
    fout.close();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}
ll smas[(ll)1e7] {};

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=0;
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>=i){
            smas[i]=tmp+1;
            tmp++;
        }
        tmp=smas[i];
        //cout << smas[i]  << ' ' ;
    }
    cout << tmp << endl;

    fin.close();
    fout.close();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}
    ll smas[(ll)1e7] {};

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=0;
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>=i){
            smas[i]=tmp+1;
            tmp++;
        }
        else
            tmp=smas[i];
        cout << smas[i]  << ' ' ;
    }
    cout << smas[n]+1 << endl;

    fin.close();
    fout.close();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=0;
    ll smas[(ll)1e6] {};
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas+1, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>=i){
            smas[i]=tmp+1;
            tmp++;
        }
        else
            tmp=smas[i];
    }
    cout << smas[n]+1;

    fin.close();
    fout.close();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (long long i=0; i<n; i++)
#define eps 1e-9

using namespace std;

typedef long long ll;

double sqr(double a){
    return a*a;
}
bool doubleEqual(double a, double b){
    return fabs(a-b)<1e-9;
}
bool doubleLessOrEqual(double a, double b){
    return a<b || doubleEqual(a, b);
}
bool doubleLess(double a, double b){
    return a<b && !doubleEqual(a, b);
}
bool doubleGreaterOrEqual(double a, double b){
    return a>b || doubleEqual(a, b);
}
bool doubleGreater(double a, double b){
    return a>b && !doubleEqual(a, b);
}
double mySqrt(double a){
    if (doubleLess(a,0)) throw "sqrt(-1)";
    if (a<0) return 0;
    return sqrt(a);
}

struct Point{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x, double y): x(x), y(y) {}
    void scan(){
        scanf("%lf %lf", &x, &y);
    }
    void print() const{
        printf("%.10lf %.10lf\n", x, y);
    }
    Point operator+(const Point &p) const {
        return Point(x+p.x, y+p.y);
    }
    Point operator-(const Point &p) const {
        return Point(x-p.x, y-p.y);
    }
    Point operator-() const {
        return Point(-x, -y);
    }
    Point operator*(double k) const {
        return Point(x*k, y*k);
    }
    Point operator/(double k) const {
        return Point(x/k, y/k);
    }
    double operator%(const Point &p) const {
        return x*p.x+y*p.y;
    }
    double operator*(const Point &p) const {
        return x*p.y-y*p.x;
    }
    double length() const {
        return mySqrt(*this % *this);
    }
    double distTo(const Point &p) const {
        return (*this -p).length();
    }
    double distTo(const Point &A, const Point &B) const {
        double d=A.distTo(B);
        if (doubleEqual(d,0)){
            throw "A = B";
        }
        double s = (*this - A) * (*this - B);
        return fabs(s)/d;
    }
    Point normalize(double k=1) const {
        double len = length();
        if(doubleEqual(len, 0)) {
            if (doubleEqual(k, 0)){
                return Point();

            }
            throw "zero-size vector";
        }
        return *this*(k/len);
    }
    Point getH(const Point &A, const Point&B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k=v%u/v.length();
        v=v.normalize(k);
        Point H=A+v;
        return H;
    }
    Point rotate() const {
        return Point(-y, x);
    }
    Point rotate(double alpha) const {
        return rotate(cos(alpha), sin(alpha));
    }
    Point rotate(double cosa, double sina) const {
        Point v = *this;
        Point u = v.rotate();
        Point w = v*cosa + u*sina;
        return w;
    }
    bool isZero() const{
        return doubleEqual(x, 0) && doubleEqual(y, 0);
    }
    bool isOnline(const Point &A, const Point &B) const {
        return doubleEqual((A-*this)*(B-*this), 0);
    }
    bool isInSegment(const Point &A, const Point &B) const {
        return doubleLessOrEqual((A-*this)%(B-*this), 0);
    }
    bool isInSegmentStricly(const Point &A, const Point &B) const {
        return doubleLess((A-*this)%(B-*this), 0);
    }
    double getAngle() const {
        return atan2(y, x);
    }
    double getAngle(Point u) const {
        return atan2(*this*u, *this%u);
    }
};

int getIntersection(const Point &A, const Point &B, const Point &C, const Point &D, Point &O) {
    Point v = B-A;
    double s1 = (C-A)*(D-A);
    double s2 = (D-B)*(C-B);
    double s = s1+s2;
    if (doubleEqual(s, 0)){
        if (!A.isOnline(C,D))
            return 0;
        return 2;
    }
    v = v/s;
    v = v*s1;
    O = A+v;
    return 1;
}

int getIntersection(const Point &A, double rA, const Point &B, double rB, Point &M, Point &N){
    double d=A.distTo(B);
    if (doubleLess(rA+rB, d) || doubleLess(d, fabs(rA-rB))){
        return 0;
    }
    double a = (sqr(rA)-sqr(rB) + sqr(d))/2/d;
    double h=mySqrt(sqr(rA)-sqr(a));
    Point v = B-A;
    Point u = v.rotate();
    v = v.normalize(a);
    u = u.normalize(h);
    Point H=A+v;
    M=H+u;
    N=H-u;
    if (u.isZero())
        return 1;
    return 2;
}

int getIntersection(const Point &A, const Point &B, const Point &O, double r, Point &M, Point &N){
    double h = O.distTo(A,B);
    if (doubleLess(r, h)){
        return 0;
    }
    Point H=O.getH(A,B);
    Point v=B-A;
    double k=mySqrt(sqr(r)-sqr(h));
    v=v.normalize(k);
    M=H+v;
    N=H-v;
    if(v.isZero())
        return 1;
    return 2;
}

struct cmp{
    bool operator()(const string &a, const string &b){
        return a+b<b+a;
    }
};

ll GCD(ll a, ll b){
    return (!b?a:GCD(b, a%b));
}

ll POW(ll a, ll b){
    return (!b?1:b==1?a:b%2?POW(a,b>>1)*POW(a,b>>1)*a:POW(a,b>>1)*POW(a,b>>1));
}

int main(){
    ifstream fin("file.in");
    ofstream fout("file.out");
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);

    ll n, m, res=0, tmp=0;
    ll smas[(ll)1e6] {};
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> smas[i];
    }
    sort(smas, smas+n+1);
    for (int i=1; i<=n; i++){
        if (smas[i]>=i){
            smas[i]=tmp+1;
            tmp++;
        }
        else
            tmp=smas[i];
    }
    cout << smas[n]+1;

    fin.close();
    fout.close();
    return 0;
}