#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int inf = 1e9;
const int mod = 1e9 + 7;
int n;
long long k;
long long a[N];
long long psum[N];
long long chk(long long mid) {
  long long re = 1e18;
  for (int i = 1; i <= n; i++) {
    long long val1 = a[i];
    long long val2 = a[i] + mid;
    long long tmp1 = (i - 1) * val1 - psum[i - 1];
    long long pos = upper_bound(a + 1, a + n + 1, val2) - a;
    long long tmp2 = (psum[n] - psum[pos - 1]) - ((n - pos + 1) * val2);
    re = min(re, tmp1 + tmp2);
  }
  for (int i = 1; i <= n; i++) {
    long long val1 = a[i] - mid;
    long long val2 = a[i];
    long long pos = lower_bound(a + 1, a + n + 1, val1) - a;
    pos--;
    long long tmp1 = (pos)*val1 - psum[pos];
    long long tmp2 = (psum[n] - psum[i - 1]) - ((n - i + 1) * val2);
    re = min(re, tmp1 + tmp2);
  }
  return re;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) psum[i] = psum[i - 1] + a[i];
  long long l = 0, h = a[n] - a[1], mid;
  long long ans = h;
  while (l <= h) {
    mid = (l + h) / 2;
    if (chk(mid) <= k) {
      ans = mid;
      h = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << '\n';
  return 0;
}
