#include <bits/stdc++.h>
using namespace std;
int x[500001];
int N, k;
bool tmax(int t) {
  int s = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (x[i] > t) s += x[i] - t;
    if (s > k) return false;
  }
  return true;
}
bool tmin(int t) {
  int s = 0;
  for (int i = 0; i < N; i++) {
    if (x[i] < t) s += t - x[i];
    if (s > k) return false;
  }
  return true;
}
int main() {
  cin >> N >> k;
  long long s = 0;
  for (int i = 0; i < N; i++) scanf("%d", &x[i]), s += x[i];
  int r = s % N;
  int vmax = -1, vmin = -1;
  int lo = 1, hi = 1000000000;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (!tmin(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  vmin = min(--lo, (int)(s / N));
  lo = 1, hi = 1000000000;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (tmax(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  vmax = max(lo, (int)(s / N + (s % N > 0)));
  cout << (vmax - vmin) << endl;
  return 0;
  return 0;
}
