#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = 2147483647;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> arr(n);
  long long sm = 0;
  for (__typeof(0) i = (0); i < (n); ++i) {
    int x;
    scanf("%d", &arr[i]);
    sm += arr[i];
  }
  long long lo = 0, hi = 2000000000, res = 0;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    long long need = 0;
    for (__typeof(0) i = (0); i < (n); ++i) {
      need += max(0LL, mid - arr[i]);
    }
    if (need <= k) {
      res = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  lo = 0, hi = 2000000000;
  long long res2 = INF;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    long long have = 0;
    for (__typeof(0) i = (0); i < (n); ++i) {
      have += max(0LL, arr[i] - mid);
    }
    if (have <= k) {
      res2 = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  if (res >= res2) {
    cout << (sm % n == 0 ? 0 : 1) << endl;
  } else {
    cout << max(0LL, res2 - res) << endl;
  }
  return 0;
}
