#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
ll modpow(ll a, ll b, ll mod = (ll)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int DEBUG = 1;
const int mxn = 5e5, oo = 1e9;
int n, k;
int a[mxn];
ll c[mxn];
void solve() {
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  for (int i = 0; i < n; i++) c[i] = a[i] + (i ? c[i - 1] : 0);
  ll l = 0;
  for (int b = 30 - 1; b >= 0; b--)
    if (l + (1LL << b) <= oo) {
      ll mid = l + (1LL << b);
      ll cost = 0;
      for (int i = 0; i < n; i++) cost += max(0LL, mid - a[i]);
      if (cost <= k) l += (1LL << b);
    }
  ll r = 0;
  for (int b = 30 - 1; b >= 0; b--)
    if (r + (1LL << b) <= oo) {
      ll mid = r + (1 << b);
      ll cost = 0;
      for (int i = 0; i < n; i++) cost += max(0LL, a[i] - mid);
      if (cost > k) r += (1 << b);
    }
  if (l < ++r)
    cout << r - l << endl;
  else
    cout << (c[n - 1] % n != 0) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
