#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
const long long mod = 1e9 + 7;
const long long inf = 2e18 + 5;
const long long nax = 100100;
long long n, k;
vector<long long> a;
bool p(long long x) {
  vector<long long> b = a;
  long long s1, s2;
  s1 = s2 = 0;
  for (long long i = (0); i < (n); i++) {
    if (b[i] < x) {
      s1 += (x - b[i]);
      b[i] = x;
    }
  }
  if (s1 > k) return 0;
  for (long long i = (0); i < (n); i++) {
    if (b[i] > x) {
      s2 += (b[i] - x);
    }
  }
  return s2 >= s1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  a = vector<long long>(n);
  for (long long i = (0); i < (n); i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long sum = 0;
  for (auto x : a) sum += x;
  long long lo = 1;
  long long hi = 1e9;
  while (hi > lo) {
    long long mid = (hi + lo) / 2;
    if (p(mid) == 0) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  long long nin = hi - 1;
  for (long long i = (0); i < (n); i++) a[i] = max(nin, a[i]);
  long long nix = a[n - 1];
  long long curr = 0;
  long long mult = 1;
  for (long long i = (n - 1); i > (0); --i) {
    long long z = (a[i] - a[i - 1]) * mult;
    if (curr + z <= k) {
      curr += z;
      nix = a[i - 1];
    } else {
      long long rem = k - curr;
      long long delta = rem / mult;
      nix -= delta;
      break;
    }
    mult++;
  }
  long long res = (sum % n != 0);
  res = max(res, nix - nin);
  cout << res;
  return 0;
}
