#include <bits/stdc++.h>
using namespace std;
int n, k;
int c[500000 + 3];
long long total = 0;
bool okay(int x, int flag) {
  long long days = 0;
  for (int i = 0; i < n; i++) {
    if (!flag)
      days += max(0, x - c[i]);
    else
      days += max(0, c[i] - x);
  }
  return (days <= k);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    total += c[i];
  }
  sort(c, c + n);
  int L, H, mid;
  int mini, maxi;
  L = c[0], H = total / n + 1;
  while (L + 1 < H) {
    mid = (L + H) >> 1;
    if (okay(mid, 0))
      L = mid;
    else
      H = mid;
  }
  mini = L;
  L = total / n - (total % n == 0), H = c[n - 1];
  while (L + 1 < H) {
    mid = (L + H) >> 1;
    if (okay(mid, 1))
      H = mid;
    else
      L = mid;
  }
  maxi = H;
  cout << maxi - mini << endl;
}
