#include <bits/stdc++.h>
using namespace std;
void addmod(int &a, long long b) {
  a = (a + b);
  if (a >= 1000000007) a -= 1000000007;
}
void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
int getint() {
  int a;
  scanf("%d", &a);
  return a;
}
long long getll() {
  long long a;
  scanf("%I64d", &a);
  return a;
}
int main() {
  long long n = getint(), k = getint();
  long long *a = new long long[n];
  for (auto i = 0; i < n; i++) {
    a[i] = getint();
  }
  sort(a, a + n);
  long long lo = 0, hi = 1000000007, mid, req, has;
  while (lo + 1 < hi) {
    mid = (lo + hi) / 2;
    req = 0, has = 0;
    for (int i = 0; i < n; i++)
      if (a[i] < mid)
        req += mid - a[i];
      else
        has += a[i] - mid;
    if (req <= has && req <= k)
      lo = mid;
    else
      hi = mid;
  }
  req = 0;
  long long LO = lo;
  for (int i = 0; i < n; i++)
    if (a[i] < lo) req += lo - a[i];
  lo--;
  hi = a[n - 1];
  while (lo + 1 < hi) {
    mid = (lo + hi) / 2;
    has = 0, req = 0;
    for (int i = 0; i < n; i++)
      if (a[i] > mid)
        has += a[i] - mid;
      else
        req += mid - a[i];
    if (has <= k && has <= req)
      hi = mid;
    else
      lo = mid;
  }
  cout << hi - LO << endl;
  return 0;
}
