#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> dxy[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
long long int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const long long MAXN = 55, MOD = 1000000007, INF = ((1ll << 60) - 1) * 2 + 1;
mt19937 Umer(1337228);
long long int n, m;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  map<long long int, long long int> mp;
  long long int a;
  for (long long int i = 0; i < (n); ++i) {
    cin >> a;
    ++mp[a];
  }
  while (m > 0 && mp.size() > 1) {
    pair<long long int, long long int> last = *(--mp.end());
    pair<long long int, long long int> first = *mp.begin();
    if (last.second < first.second) {
      mp.erase(last.first);
      pair<long long int, long long int> newLast = *(--mp.end());
      if ((last.first - newLast.first) * last.second <= m) {
        m -= (last.first - newLast.first) * last.second;
        (--mp.end())->second += last.second;
      } else {
        last.first -= m / last.second;
        m = 0;
        mp.insert(last);
      }
    } else {
      mp.erase(first.first);
      pair<long long int, long long int> newFirst = *mp.begin();
      if ((newFirst.first - first.first) * first.second <= m) {
        m -= (newFirst.first - first.first) * first.second;
        mp.begin()->second += first.second;
      } else {
        first.first += m / first.second;
        m = 0;
        mp.insert(first);
      }
    }
  }
  cout << (--mp.end())->first - mp.begin()->first;
}
