#include <bits/stdc++.h>
using namespace std;
int const INF = 2e9;
int const MAX = 5e5 + 5;
int n, k, ma, mi;
long long c[MAX];
bool ok1(long long x) {
  long long res = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (c[i] > x)
      res += c[i] - x;
    else
      break;
  }
  return res <= k;
}
bool ok2(long long x) {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (x > c[i])
      res += x - c[i];
    else
      break;
  }
  return res <= k;
}
int main() {
  long long sum = 0;
  long long MA = 0, MI = INF;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &c[i]);
    sum += c[i];
    MA = max(MA, c[i]);
    MI = min(MI, c[i]);
  }
  if (sum % n == 0)
    ma = mi = sum / n;
  else {
    ma = sum / n + 1;
    mi = sum / n;
  }
  int rma = 0, lma = 0;
  sort(c, c + n);
  int l = ma, r = MA;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (ok1(mid)) {
      r = mid - 1;
      rma = mid;
    } else
      l = mid + 1;
  }
  l = MI, r = mi;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (ok2(mid)) {
      l = mid + 1;
      lma = mid;
    } else
      r = mid - 1;
  }
  printf("%d\n", rma - lma);
  return 0;
}
