#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 1e9;
const int mod = 1e9 + 7;
long long n, k;
long long ara[400000];
long long csum[400000];
long long moves(long long mid) {
  long long re = 1e17;
  for (long long i = 1; i <= n; i++) {
    long long cur1 = ara[i];
    long long cur2 = ara[i] + mid;
    long long pos1 = i - 1;
    long long pos2 = upper_bound(ara + 1, ara + n + 1, cur2) - ara;
    long long tmp1 = (i - 1) * ara[i] - csum[i - 1];
    long long tmp2 = (csum[n] - csum[pos2 - 1]) - cur2 * (n - pos2 + 1);
    re = min(re, tmp1 + tmp2);
  }
  for (long long i = 1; i <= n; i++) {
    long long cur1 = ara[i] - mid;
    long long cur2 = ara[i];
    long long pos1 = lower_bound(ara + 1, ara + n + 1, cur1) - ara;
    pos1--;
    long long pos2 = i;
    long long tmp1 = pos1 * cur1 - csum[pos1];
    long long tmp2 = (csum[n] - csum[pos2]) - cur2 * (n - pos2);
    re = min(re, tmp1 + tmp2);
  }
  return re;
}
int main(int argc, char const *argv[]) {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) scanf("%lld", &ara[i]);
  sort(ara + 1, ara + n + 1);
  for (long long i = 1; i <= n; i++) csum[i] = csum[i - 1] + ara[i];
  long long lo = 0, hi = ara[n] - ara[1];
  long long anss = hi;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    if (moves(mid) <= k) {
      anss = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << anss << '\n';
  return 0;
}
