#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int N = 5e5 + 25;
int a[N];
int n, k;
int cmp(int x, int y) { return x > y; }
int check(int x) {
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > x) {
      sum += (long long)(a[i] - x);
    } else
      break;
  }
  if (sum > k) return 0;
  return 1;
}
int ok(int x) {
  long long sum = 0;
  for (int i = n; i > 0; i--) {
    if (a[i] < x) {
      sum += (long long)(x - a[i]);
    } else
      break;
  }
  if (sum > k) return 0;
  return 1;
}
int main() {
  int ans;
  long long s = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s += (long long)a[i];
  int mmin, mmax;
  if (s % n == 0) {
    mmin = mmax = s / n;
  } else {
    mmin = s / n;
    mmax = mmin + 1;
  }
  sort(a + 1, a + n + 1, cmp);
  int l = mmax, r = 1e9 + 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (!check(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  ans = l;
  l = 1, r = mmin;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (ok(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  ans = ans - r;
  cout << ans << "\n";
  return 0;
}
