#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long M = 1e9 + 7;
long long n;
long long k;
vector<long long> v;
vector<long long> pref;
long long check2(long long minn, long long maxx) {
  long long ans = 0;
  long long x = lower_bound(v.begin(), v.end(), minn) - v.begin();
  if (x != 0) {
    long long done = pref[x - 1];
    ans += (minn * x) - done;
  }
  long long y = upper_bound(v.begin(), v.end(), maxx) - v.begin();
  if (y != v.size()) {
    y--;
    long long got = pref[n - 1] - pref[y];
    long long tobe = maxx * (n - 1 - y);
    ans += (got - tobe);
  }
  if (ans <= k) return 1;
  return 0;
}
long long check(long long x) {
  for (long long i = 0; i <= n - 1; i++) {
    long long xx = check2(v[i], v[i] + x);
    long long yy = check2(v[i] - x, v[i]);
    if (xx == 1 || yy == 1) {
      return 1;
    }
  }
  return 0;
}
long long binsearch(long long lo, long long hi) {
  while (lo < hi) {
    long long mid = (lo + hi) >> 1;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (long long i = 0; i <= n - 1; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
  }
  sort((v).begin(), (v).end());
  pref.push_back(v[0]);
  for (long long i = 1; i < n; i++) {
    pref.push_back(pref[i - 1] + v[i]);
  }
  cout << binsearch(0, v[n - 1] - v[0]) << "\n";
}
