#include <bits/stdc++.h>
using namespace std;
template <class t>
t mag(t a) {
  return a > 0 ? a : -a;
}
template <class T, class U>
T cdiv(T num, U den) {
  return (num / den) + ((num % den) > 0);
}
std::ifstream term("/dev/tty");
std::string tempstring;
using ll = int_fast64_t;
using ii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
const int sij = 400010;
const ll mod = 1000000007ll;
ll n, k, vec[sij], sum[sij];
int esc(int tcase) {
  cin >> n >> k;
  for (auto i = 0; i != n; i++) cin >> vec[i];
  sort(vec, vec + n);
  partial_sum(vec, vec + n, sum);
  auto pred1 = [&](ll mini, ll maxi) -> bool {
    auto it = upper_bound(vec, vec + n, mini) - vec;
    auto it2 = upper_bound(vec, vec + n, maxi) - vec;
    ll tot = (mini * it) - sum[it - 1] + sum[n - 1] - sum[it2 - 1] -
             maxi * (n - it2);
    return tot <= k;
  };
  ll prt = vec[n - 1] - vec[0];
  for (auto i = 0; i != n; i++) {
    ll l = vec[i], r = vec[n - 1];
    while (l < r) {
      ll mid = l + (r - l) / 2;
      auto xx = pred1(vec[i], mid);
      if (xx) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
    if (pred1(vec[i], l)) prt = min(prt, l - vec[i]);
    l = vec[0], r = vec[i];
    while (l < r) {
      ll mid = l + (r - l + 1) / 2;
      auto xx = pred1(mid, vec[i]);
      if (xx) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }
    if (!pred1(l, vec[i])) continue;
    prt = min(prt, vec[i] - l);
  }
  cout << prt << '\n';
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  for (int i = 1; i <= tc; i++) esc(i);
}
