#include <bits/stdc++.h>
using namespace std;
void load() {}
const long long inf = 4e18;
long long a[100100], n;
long long k;
long long maxi, mini;
bool check(int x) {
  long long sumR[n];
  sumR[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) sumR[i] = sumR[i + 1] + a[i];
  long long sumL[n];
  sumL[0] = a[0];
  for (int i = 1; i < n; i++) sumL[i] = sumL[i - 1] + a[i];
  long long mini = inf;
  for (int i = 0; i < n; i++) {
    long long l = i, r = upper_bound(a, a + n, a[i] + x) - a;
    long long sum = 0;
    if (l) sum += l * a[l] - sumL[l - 1];
    if (r < n) sum += sumR[r] - (a[i] + x) * (n - r);
    mini = min(mini, sum);
  }
  for (int i = n - 1; i >= 0; i--) {
    long long r = i, l = lower_bound(a, a + n, a[i] - x) - a;
    long long sum = 0;
    if (l) sum += (a[i] - x) * l - sumL[l - 1];
    if (r < n) sum += sumR[r + 1] - a[r] * (n - r - 1);
    mini = min(mini, sum);
  }
  return mini <= k;
}
void solve() {
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", a + i);
  sort(a, a + n);
  maxi = *max_element(a, a + n);
  mini = *min_element(a, a + n);
  int lo = 0, hi = maxi - mini;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  printf("%d\n", lo);
}
int main() {
  load();
  solve();
  return 0;
}
