#include <bits/stdc++.h>
using namespace std;
const int kN = 5e5 + 5;
int n, k, C[kN];
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> C[i];
  sort(C, C + n);
  int64_t sm = accumulate(C, C + n, 0LL), av = sm / n;
  auto IsMinPossible = [&](int val) -> bool {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (C[i] >= val) break;
      cnt += val - C[i];
      if (cnt > k) return false;
    }
    return true;
  };
  auto IsMaxPossible = [&](int val) -> bool {
    int cnt = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (C[i] <= val) break;
      cnt += C[i] - val;
      if (cnt > k) return false;
    }
    return true;
  };
  int lo = C[0], hi = C[n - 1], l, h;
  while (lo <= hi) {
    int mid = lo + ((hi - lo) >> 1);
    if (IsMinPossible(mid))
      l = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  l = min(l, (int)av), lo = l, hi = C[n - 1];
  while (lo <= hi) {
    int mid = lo + ((hi - lo) >> 1);
    if (IsMaxPossible(mid))
      h = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  cout << (h - l == 0 ? av * n == sm ? 0 : 1 : h - l) << endl;
  return 0;
}
