#include <bits/stdc++.h>
using namespace std;
long long a[500005], n, k;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  long long lo = 1, hi = 1e9, mid;
  while (lo <= hi) {
    long long need = 0, avail = 0;
    mid = (lo + (hi - lo) / 2);
    for (long long i = 1; i <= n; i++)
      if (a[i] >= mid)
        avail += (a[i] - mid);
      else
        need += (mid - a[i]);
    if (need <= avail && need <= k)
      lo = mid + 1;
    else
      hi = mid - 1;
  }
  long long low = hi;
  lo = 1, hi = 1e9;
  while (lo <= hi) {
    long long need = 0, avail = 0;
    mid = (lo + (hi - lo) / 2);
    for (long long i = 1; i <= n; i++)
      if (a[i] < mid)
        avail += (mid - a[i]);
      else
        need += (a[i] - mid);
    if (avail >= need && need <= k)
      hi = mid - 1;
    else
      lo = mid + 1;
  }
  long long high = lo;
  cout << (high - low) << "\n";
  return 0;
}
