#include <bits/stdc++.h>
using namespace std;
long long int c[500005];
long long int n, k;
bool f(long long int x) {
  long long int i, opns = 0;
  for (i = 0; i < n; i++) opns = opns + max((long long int)0, x - c[i]);
  if (opns <= k) return false;
  return true;
}
bool ff(long long int x) {
  long long int i, opns = 0;
  for (i = 0; i < n; i++) opns = opns + max((long long int)0, c[i] - x);
  if (opns <= k) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, mini, l, h, m, maxi, tota = 0, oma = 0, omi = 1000000005;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> c[i];
    tota = tota + c[i];
    omi = min(c[i], omi);
    oma = max(c[i], oma);
  }
  l = omi;
  h = oma;
  while (l < h) {
    m = (l + h + 1) / 2;
    if (f(m) == true)
      h = m - 1;
    else
      l = m;
  }
  mini = l;
  l = omi;
  h = oma;
  while (l < h) {
    m = (l + h) / 2;
    if (ff(m) == true)
      h = m;
    else
      l = m + 1;
  }
  maxi = l;
  if (mini < maxi)
    cout << (maxi - mini) << "\n";
  else {
    if (tota % n)
      cout << "1\n";
    else
      cout << "0\n";
  }
  return 0;
}
