#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
long long n, k, sum;
long long a[maxn];
long long goal[maxn];
long long max(long long x, long long y) { return x > y ? x : y; }
long long cntmx = -9e18, cntmn = 9e18;
void solve3() {
  long long m = k;
  for (register int i = n; i >= 1; --i) {
    if (m >= (n - i + 1) * (a[i] - a[i - 1])) {
      m -= (n - i + 1) * (a[i] - a[i - 1]);
    } else {
      cntmn = a[i] - m / (n - i + 1);
      break;
    }
  }
  if (cntmn == 9e18) cntmn = a[1] - m / n;
  m = k;
  for (register int i = 1; i <= n; ++i) {
    if (m >= i * (a[i + 1] - a[i])) {
      m -= i * (a[i + 1] - a[i]);
    } else {
      cntmx = a[i] + m / i;
      break;
    }
  }
  if (cntmx == -9e18) cntmx = a[n] + m;
  if (cntmn - cntmx <= 0) {
    if (sum % n == 0)
      printf("0\n");
    else
      printf("1\n");
  } else
    printf("%lld\n", max(0LL, cntmn - cntmx));
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (register int i = 1; i <= n; ++i) scanf("%lld", &a[i]), sum += a[i];
  sort(a + 1, a + n + 1);
  solve3();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
