#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
const long long mod = 1e9 + 7;
vector<long long> v;
map<long long, long long> m;
void solve() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
    m[x]++;
  }
  sort(v.begin(), v.end());
  v.resize(distance(v.begin(), unique(v.begin(), v.end())));
  long long l = 0, r = v.size() - 1;
  long long cl = m[v[l]], cr = m[v[r]];
  long long ans = v[r] - v[l];
  long long d = 0;
  while (k && l < r) {
    long long c = 1;
    d = 0;
    if (cl <= cr) {
      if (k >= (cl * (v[l + 1] - v[l]))) {
        k -= cl * (v[l + 1] - v[l]);
        l++;
        cl += m[v[l]];
      } else {
        d = k / cl;
        k = 0;
      }
    } else {
      c = 2;
      if (k >= (cr * (v[r] - v[r - 1]))) {
        k -= cr * (v[r] - v[r - 1]);
        r--;
        cr += m[v[r]];
      } else {
        d = k / cr;
        k = 0;
      }
    }
  }
  ans = v[r] - v[l];
  ans -= d;
  ans = max(0LL, ans);
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
