#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int INF = 1e9;
long long c[maxn], sum[maxn], k, n, l, r, ans, up, down;
long long mmin, mmax;
bool Check(long long x, int t) {
  bool flag = false;
  int pos = upper_bound(c + 1, c + 1 + n, x) - c;
  if (t == 0) {
    if (sum[pos - 1] + k >= (pos - 1) * x) flag = true;
  }
  if (t == 1) {
    if (sum[n] - sum[pos - 1] - k <= (n - pos + 1) * x) flag = true;
  }
  return flag;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &c[i]);
  sort(c + 1, c + 1 + n);
  for (int i = 1; i <= n; i++) sum[i] = c[i] + sum[i - 1];
  down = sum[n] / n;
  if (sum[n] % n)
    up = down + 1;
  else
    up = down;
  l = 0, r = INF;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (Check(mid, 0)) {
      mmin = mid;
      if (mmin >= down) break;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  mmin = min(down, mmin);
  l = 0, r = INF;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (Check(mid, 1)) {
      mmax = mid;
      if (mmax <= up) break;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  mmax = max(up, mmax);
  ans = mmax - mmin;
  if (ans < 0) ans = 0;
  printf("%lld\n", ans);
}
