#include <bits/stdc++.h>
using namespace std;
long long a[500002];
long long n, k;
bool karapoqrlini(long long x) {
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += max(1ll * 0, x - a[i]);
    if (ans > k) return false;
  }
  return true;
}
bool karametslini(long long x) {
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += max(1ll * 0, a[i] - x);
    if (ans > k) return false;
  }
  return true;
}
int main() {
  scanf("%lld%lld", &n, &k);
  long long sm = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%lld", a + i);
    sm += a[i];
  }
  long long l = 1, r = 1000 * 1000 * 1000 + 1;
  while (r > l + 1) {
    long long m = (r + l) / 2;
    if (karapoqrlini(m))
      l = m;
    else
      r = m;
  }
  long long r1 = 1, l1 = 1000 * 1000 * 1000 + 1;
  while (l1 > r1 + 1) {
    long long m = (r1 + l1) / 2;
    if (karametslini(m))
      l1 = m;
    else
      r1 = m;
  }
  cout << max(l1 - l, 1ll * (sm % n == 0 ? 0 : 1)) << endl;
  return 0;
}
