#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  for (unsigned long long i = 0; i < a.size(); i++)
    os << a[i] << (i < a.size() - 1 ? ", " : "");
  os << ']';
  return os;
}
long long n;
long long amount;
long long a[N];
long long sumL[N], sumR[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> amount;
  for (long long i = (1); i <= (n); i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  long long L = 1, R = n;
  long long ans = 0;
  while (true) {
    ans = a[R] - a[L];
    if (L == R) break;
    long long costL = L;
    long long limL = a[L + 1] - a[L];
    long long costR = n - R + 1;
    long long limR = a[R] - a[R - 1];
    if (limL == 0)
      L++;
    else if (limR == 0)
      R--;
    else if (costL < costR) {
      long long use = min(limL, amount / costL);
      if (use == 0) break;
      amount -= use * costL;
      if (use == limL)
        L++;
      else {
        ans = a[R] - a[L] - use;
        break;
      }
    } else {
      long long use = min(limR, amount / costR);
      if (use == 0) break;
      amount -= use * costR;
      if (use == limR)
        R--;
      else {
        ans = a[R] - a[L] - use;
        break;
      }
    }
  }
  cout << ans << '\n';
}
