#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <int sz>
class parsator {
  array<char, sz> buf;
  char* poz;
  const char* const after_last;
  void refill() {
    if (poz == after_last) {
      poz = &buf[0];
      cin.read(&buf[0], sz);
    }
  }

 public:
  parsator() : poz(&buf[0] + sz), after_last(poz) { refill(); }
  parsator<sz>& operator>>(ll& x) {
    x = 0;
    for (; !isdigit(*poz); ++poz, refill())
      ;
    for (; isdigit(*poz); ++poz, refill()) {
      x = 10 * x + *poz - '0';
    }
    return *this;
  }
};
template <typename T>
ll my_upper_bound(ll st, ll dr, T&& t) {
  for (ll step = 1 << (ll)(log2(dr - st + 1)); step; step /= 2) {
    if (st + step <= dr && t(st + step)) {
      st += step;
    }
  }
  return st;
}
template <typename T>
ll my_lower_bound(ll st, ll dr, T&& t) {
  for (ll step = 1 << (ll)(log2(dr - st + 1)); step; step /= 2) {
    if (dr - step >= st && t(dr - step)) {
      dr -= step;
    }
  }
  return dr;
}
int main() {
  ll n, k;
  auto f = parsator<1000>();
  f >> n >> k;
  vector<ll> v(n);
  for (auto& x : v) {
    f >> x;
  }
  sort(begin(v), end(v));
  vector<ll> parts(v.size() + 1);
  partial_sum(begin(v), end(v), begin(parts) + 1);
  const ll M = *max_element(begin(v), end(v)),
           m = *min_element(begin(v), end(v));
  const ll lower = my_upper_bound(
               m, M,
               [&v, &parts, k](const ll x) {
                 const ll index = lower_bound(begin(v), end(v), x) - begin(v);
                 return index * x - parts[index] <= k;
               }),
           upper = my_lower_bound(m, M, [&v, &parts, k, n](const ll x) {
             const ll index = upper_bound(begin(v), end(v), x) - begin(v);
             return parts[n] - parts[index] - ((ll)n - index) * x <= k;
           });
  if (upper - lower <= 0) {
    cout << (accumulate(begin(v), end(v), 0ll) % n != 0) << '\n';
  } else {
    cout << max(upper - lower, 0ll) << '\n';
  }
  return 0;
}
