#include <bits/stdc++.h>
using namespace std;
const int MAXINT = 500010;
int n, k, c[MAXINT] = {};
int check(int);
int check2(int);
int main() {
  int temp, tm, ans = 0, l = 0, r = 0x3f3f3f3f, mid, rich, poor, p = 0;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", c + i);
  }
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (check2(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  poor = l;
  tm = k;
  for (int i = 0; i < n; i++) {
    tm -= max(0, poor - c[i]);
    c[i] = max(c[i], poor);
  }
  while (tm > 0 && p != n) {
    if (c[p] == poor) {
      c[p]++;
      tm--;
    }
    p++;
  }
  l = 0;
  r = 0x3f3f3f3f, p = 0;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  rich = r;
  tm = k;
  for (int i = 0; i < n; i++) {
    tm -= max(0, c[i] - rich);
    c[i] = min(c[i], rich);
  }
  while (tm > 0 && p != n) {
    if (c[p] == rich) {
      c[p]--;
      tm--;
    }
    p++;
  }
  cout << *max_element(c, c + n) - *min_element(c, c + n) << endl;
  return 0;
}
int check(int a) {
  long long tt = 0;
  for (int i = 0; i < n; i++) {
    tt += max(0, c[i] - a);
  }
  if (tt > k) return 0;
  return 1;
}
int check2(int a) {
  long long tt = 0;
  for (int i = 0; i < n; i++) {
    tt += max(0, a - c[i]);
  }
  if (tt > k) return 0;
  return 1;
}
