#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long val;
  map<long long, long long> counts;
  for (long long i = 0; i < n; ++i) {
    cin >> val;
    if (counts.count(val))
      ++counts[val];
    else
      counts[val] = 1;
  }
  deque<vector<long long>> pairs;
  for (auto [num, count] : counts) {
    pairs.push_back(vector<long long>{num, count});
  }
  sort(pairs.begin(), pairs.end());
  while (k) {
    if (pairs.size() == 1) {
      cout << 0 << endl;
      exit(0);
    }
    if (pairs.back()[1] < pairs.front()[1]) {
      vector<long long> current = pairs.back();
      pairs.pop_back();
      vector<long long> cmp = pairs.back();
      long long spent_k = min(k, (current[0] - cmp[0]) * current[1]);
      k -= spent_k;
      if (spent_k == (current[0] - cmp[0]) * current[1]) {
        pairs.back()[1] += current[1];
      } else {
        cout << current[0] - (spent_k / current[1]) - pairs.front()[0] << endl;
        exit(0);
      }
    } else {
      vector<long long> current = pairs.front();
      pairs.pop_front();
      vector<long long> cmp = pairs.front();
      long long spent_k = min(k, (cmp[0] - current[0]) * current[1]);
      k -= spent_k;
      if (spent_k == (cmp[0] - current[0]) * current[1]) {
        pairs.front()[1] += current[1];
      } else {
        cout << pairs.back()[0] - current[0] - (spent_k / current[1]) << endl;
        exit(0);
      }
    }
  }
  cout << pairs.back()[0] - pairs.front()[0] << endl;
}
