#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long INF = 1e18;
long long power(long long x, long long y) {
  long long t = 1;
  while (y > 0) {
    if (y % 2)
      y -= 1, t = t * x % mod;
    else
      y /= 2, x = x * x % mod;
  }
  return t;
}
long long arr[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n == 0) {
    printf("0\n");
    exit(0);
  }
  long long tot = 0;
  for (int i = 0; i < n; ++i) scanf("%lld", &arr[i]);
  sort(arr, arr + n);
  for (int i = 0; i < n; ++i) tot += arr[i];
  int a = 1;
  if (tot % n == 0) a = 0;
  long long l = arr[0], r;
  int hv = k;
  for (int i = 0; i < n; ++i) {
    if (k >= i * (arr[i] - l)) {
      k -= i * (arr[i] - l);
      l = arr[i];
    } else {
      l += k / i;
      break;
    }
  }
  r = arr[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (hv >= (n - 1 - i) * (r - arr[i])) {
      hv -= (n - 1 - i) * (r - arr[i]);
      r = arr[i];
    } else {
      r -= (hv) / (n - 1 - i);
      break;
    }
  }
  if (l < r) {
    printf("%lld\n", r - l);
  } else
    printf("%d\n", a);
  return 0;
}
