#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j;
  scanf("%d%d", &n, &k);
  vector<int> c(n, 0);
  vector<pair<int, int> > h(n, pair<int, int>(0, 0));
  for (auto &itr : c) scanf("%d", &itr);
  sort(c.begin(), c.end());
  for (i = 0; i < n; i = j) {
    for (j = i + 1; j < n && c[i] == c[j]; j++) {
    }
    h.push_back(pair<int, int>(c[i], j - i));
  }
  for (i = n; k > 0; k -= j) {
    while (i + 1 < h.size() && h.back().first == h[h.size() - 2].first) {
      h[h.size() - 2].second += h.back().second;
      h.pop_back();
    }
    while (i + 1 < h.size() && h[i].first == h[i + 1].first) {
      h[i + 1].second += h[i].second;
      i++;
    }
    if (i + 1 >= h.size() ||
        (i + 2 == h.size() && h[i].first + 1 == h[i + 1].first))
      break;
    j = min(
        min(h[i].second * (long long)(h[i + 1].first - h[i].first),
            (long long)k),
        h.back().second * (long long)(h.back().first - h[h.size() - 2].first));
    if (i + 2 == h.size() && j > min(h[i + 1].second, h[i].second) *
                                     (long long)(h[i + 1].first - h[i].first) /
                                     2) {
      j = min(h[i + 1].second, h[i].second) *
          (long long)(h[i + 1].first - h[i].first) / 2;
    }
    int mod = j % h.back().second;
    if (mod == 0)
      h.back().first -= j / h.back().second;
    else {
      h.back().first -= j / h.back().second + 1;
      int diff = h.back().second - mod;
      h.back().second = mod;
      h.push_back(pair<int, int>(h.back().first + 1, diff));
    }
    mod = j % h[i].second;
    if (mod == 0)
      h[i].first += j / h[i].second;
    else {
      h[i].first += j / h[i].second + 1;
      int diff = h[i].second - mod;
      h[i].second = mod;
      h[i - 1].first = h[i].first - 1;
      h[--i].second = diff;
    }
  }
  cout << h.back().first - h[i].first << endl;
  return 0;
}
