#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    m[a]++;
  }
  vector<pair<long long, long long>> v;
  for (auto& it : m) {
    v.push_back({it.first, it.second});
  }
  if (v.size() == 1) {
    cout << 0;
    return 0;
  }
  long long l = 0;
  long long r = (long long)(v.size()) - 1;
  while (k and l < r) {
    long long m1 = v[l].second;
    long long m2 = v[r].second;
    if (m2 < m1) {
      long long mvs = v[r].first - v[r - 1].first;
      if (mvs * v[r].second <= k) {
        k -= mvs * v[r].second;
        v[r - 1].second += v[r].second;
        r--;
      } else {
        long long z = k / v[r].second;
        v[r].first -= z;
        break;
      }
    } else {
      long long mvs = v[l + 1].first - v[l].first;
      if (mvs * v[l].second <= k) {
        k -= mvs * v[l].second;
        v[l + 1].second += v[l].second;
        l++;
      } else {
        long long z = k / v[l].second;
        v[l].first += z;
        break;
      }
    }
  }
  cout << v[r].first - v[l].first;
  return 0;
}
