#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[100005];
long long sum[100005];
long long calc(long long l, long long r) {
  long long rpos = upper_bound(a + 1, a + n + 1, r) - a,
            lpos = lower_bound(a + 1, a + n + 1, l) - a - 1;
  long long rnum = n + 1 - rpos, rsum = sum[n] - sum[rpos - 1];
  long long lnum = lpos, lsum = sum[lpos];
  long long ret = rsum - rnum * r + lnum * l - lsum;
  return ret;
}
bool check(long long x) {
  long long mn = 100000000000000000;
  for (int i = 1; i <= n; i++) {
    mn = min(mn, calc(a[i], a[i] + x));
    mn = min(mn, calc(a[i] - x, a[i]));
  }
  return mn <= k;
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.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++) sum[i] = sum[i - 1] + a[i];
  long long ub = 1e9 + 7, lb = -1, mid;
  while (ub - lb > 1) {
    mid = (ub + lb) / 2;
    if (check(mid))
      ub = mid;
    else
      lb = mid;
  }
  cout << ub << endl;
  return 0;
}
