#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &a, const vector<long long> &b) {
  for (auto k : b) cout << k << " ";
  return a;
}
const long long INF = 1e18;
const long long p = 179;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  map<long long, long long> cnt;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort((a).begin(), (a).end());
  a.resize(unique((a).begin(), (a).end()) - a.begin());
  long long sz = a.size();
  vector<long long> b(sz);
  for (long long i = 0; i < sz; i++) {
    b[i] = cnt[a[i]];
  }
  long long l = 0, r = sz - 1;
  long long ans = a[sz - 1] - a[0];
  while (l < r && k) {
    long long upl = (a[l + 1] - a[l]) * b[l];
    long long upr = (a[r] - a[r - 1]) * b[r];
    if (min(upl, upr) > k) {
      ans -= k / min(b[l], b[r]);
      break;
    } else {
      if (b[l] <= b[r]) {
        if (upl > k) {
          ans -= k / b[l];
          break;
        }
        k -= upl;
        b[l + 1] += b[l];
        b[l] = 0;
        l++;
      } else {
        if (upr > k) {
          ans -= k / b[r];
          break;
        }
        k -= upr;
        b[r - 1] += b[r];
        b[r] = 0;
        r--;
      }
      ans = a[r] - a[l];
    }
  }
  cout << ans;
}
