#include <bits/stdc++.h>
using namespace std;
inline int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
template <typename T>
inline bool smax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool smin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long c[1000000], n, k, s[1000000];
int main() {
  n = ri();
  k = ri();
  for (int i = 0; i < (n); i++) c[i] = ri();
  sort(c, c + n);
  for (int i = 0; i < (n); i++) {
    s[i] = c[i] + (i > 0 ? s[i - 1] : 0);
  }
  s[n] = s[n - 1];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long sum = 0;
  for (int i = 0; i < (n); i++) sum += c[i];
  long long xl = sum / n, xr = xl + (sum % n != 0);
  long long l = c[0], r = xl;
  while (l < r) {
    long long mid = (l + r) / 2 + 1;
    int idx = lower_bound(c, c + n, mid) - c;
    long long d = idx * mid - s[idx] + c[idx];
    if (d > k)
      r = mid - 1;
    else
      l = mid;
  }
  long long xmin = l;
  l = xr, r = c[n - 1];
  while (l < r) {
    long long mid = (l + r) / 2;
    int idx = upper_bound(c, c + n, mid) - c;
    long long d = (s[n] - s[idx] + c[idx]) - (n - idx) * mid;
    if (d > k)
      l = mid + 1;
    else
      r = mid;
  }
  long long xmax = r;
  cout << (xmax - xmin) << endl;
  return 0;
}
