#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<long long> vec;
long long vc[500005];
long long vcsum;
bool canMake(long long minv, int diff) {
  long long maxv = minv + diff;
  if ((vcsum > maxv * n) || vcsum < minv * n) return false;
  long long days = 0;
  long long upper = 0;
  long long lower = 0;
  auto it = lower_bound(vec.begin(), vec.end(), minv);
  if (it != vec.begin()) {
    auto jt = it;
    jt--;
    int idx = jt - vec.begin();
    lower += minv * (idx + 1);
    lower -= vc[idx];
  }
  auto kt = upper_bound(vec.begin(), vec.end(), maxv);
  kt--;
  int idx = kt - vec.begin();
  upper += (vcsum - vc[idx]);
  upper -= (maxv * (n - idx - 1));
  days = max(upper, lower);
  if (days <= k) return true;
  return false;
}
int canMake1(int minv) {
  auto it = lower_bound(vec.begin(), vec.end(), minv);
  long long lower = 0;
  if (it != vec.begin()) {
    auto jt = it;
    jt--;
    int idx = jt - vec.begin();
    lower += minv * (idx + 1);
    lower -= vc[idx];
  }
  if (lower > k) return -1;
  int l = 0, r = 1e9;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (canMake(minv, mid))
      r = mid;
    else
      l = mid;
  }
  if (canMake(minv, l)) return l;
  if (canMake(minv, r)) return r;
  return -1;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    vec.push_back(x);
  }
  sort(vec.begin(), vec.end());
  vc[0] = vec[0];
  for (int i = 1; i < vec.size(); i++) {
    vc[i] = vc[i - 1] + vec[i];
  }
  int l, r;
  vcsum = vc[n - 1];
  l = vc[0];
  r = vec[n - 1];
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (canMake1(mid) >= 0)
      l = mid;
    else
      r = mid;
  }
  if (canMake1(r) >= 0)
    cout << canMake1(r) << endl;
  else
    cout << canMake1(l) << endl;
  return 0;
}
