#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5 * 5 + 5;
int n, k, c[MXN];
bool can_min(int mid) {
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += max(0, mid - c[i]);
  }
  return cnt <= k;
}
bool can_max(int mid) {
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += max(0, c[i] - mid);
  }
  return cnt <= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  long long tot = 0;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    tot += c[i];
  }
  sort(c, c + n);
  int best_min, best_max;
  if (tot % n == 0) {
    best_min = best_max = tot / n;
  } else {
    best_min = tot / n;
    best_max = best_min + 1;
  }
  int m1, m2;
  int lo = c[0], hi = c[n - 1], mid;
  while (lo < hi - 1) {
    mid = (lo + hi) / 2;
    if (can_min(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  if (can_min(hi))
    m1 = hi;
  else
    m1 = lo;
  lo = c[0];
  hi = c[n - 1];
  while (lo < hi) {
    mid = (lo + hi) / 2;
    if (can_max(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  m2 = lo;
  m1 = min(m1, best_min);
  m2 = max(m2, best_max);
  cout << m2 - m1 << endl;
  return 0;
}
