#include <bits/stdc++.h>
using namespace std;
int n, k;
long long mmin, mmax, a[500005], sum;
int main() {
  scanf("%d%d", &n, &k);
  mmin = 2e9;
  mmax = -1;
  sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    sum += a[i];
    mmin = min(mmin, a[i]);
    mmax = max(mmax, a[i]);
  }
  long long s = sum;
  sum /= n;
  long long ansl, ansr;
  long long l = mmin, r = mmax + 1, mid, cur;
  while (r - l > 1) {
    mid = (l + r) >> 1;
    cur = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] < mid && a[i] <= sum) cur += mid - a[i];
    }
    if (cur <= k)
      l = mid;
    else
      r = mid;
  }
  ansl = l;
  l = mmin, r = mmax + 1;
  while (l < r) {
    mid = (l + r) >> 1;
    cur = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > mid && a[i] > sum) cur += a[i] - mid;
    }
    if (cur > k)
      l = mid + 1;
    else
      r = mid;
  }
  ansr = l;
  long long ans = ansr - ansl;
  if (ans <= 0) {
    if (sum * n == s)
      ans = 0;
    else
      ans = 1;
  }
  printf("%lld\n", ans);
  return 0;
}
