#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
long long a[MAXN], n;
bool check_min(long long x, long long k) {
  long long cnt = upper_bound(a + 1, a + n + 1, x) - a;
  for (int i = 1; i <= cnt - 1; ++i) {
    k -= (x - a[i]);
    if (k < 0) return false;
  }
  return true;
}
bool check_max(long long x, long long k) {
  long long cnt = upper_bound(a + 1, a + n + 1, x) - a;
  for (int i = cnt; i <= n; ++i) {
    k -= (a[i] - x);
    if (k < 0) return false;
  }
  return true;
}
int main() {
  long long k, sum = 0;
  scanf("%lld %lld", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
    sum += a[i];
  }
  sort(a + 1, a + n + 1);
  if (a[1] == a[n]) {
    printf("0\n");
    return 0;
  }
  long long l = a[1], r = sum / n + 1, L = a[1], R = a[n];
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (check_min(mid, k)) {
      l = mid + 1;
      L = mid;
    } else
      r = mid;
  }
  l = sum / n, r = a[n];
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (check_max(mid, k)) {
      r = mid;
      R = r;
    } else
      l = mid + 1;
  }
  printf("%lld\n", R > L ? R - L : (sum % n ? 1 : 0));
}
