#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
const long long INF = numeric_limits<long long>::max() / 2;
const long double PI = 3.1415926535898;
const long long MOD = 1e9 + 7;
const long long LIM = 1e5 + 5;
long long fpow(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = fpow(x, y / 2);
  if (y % 2 == 0)
    return (temp * temp) % MOD;
  else
    return (x * ((temp * temp) % MOD)) % MOD;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long dpl[LIM], dpr[LIM];
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (auto &x : a) cin >> x;
  ;
  sort(a.begin(), a.end());
  ;
  dpl[0] = dpr[n - 1] = 0;
  long long l = 0, r = 1e9;
  for (long long i = 1; i < n; ++i) dpl[i] = dpl[i - 1] + i * (a[i] - a[i - 1]);
  for (long long i = n - 2; i >= 0; --i)
    dpr[i] = dpr[i + 1] + (n - i - 1) * (a[i + 1] - a[i]);
  while (l < r) {
    long long mid = (l + r) / 2, mincost = INF;
    for (long long i = 0; i < n; ++i) {
      long long ele = a[i] + mid, lcost = dpl[i], rcost;
      auto itr = upper_bound(a.begin(), a.end(), ele);
      if (itr == a.end())
        rcost = 0;
      else {
        long long pos = itr - a.begin();
        rcost = dpr[pos] + (n - pos) * (a[pos] - ele);
      }
      mincost = min(mincost, lcost + rcost);
    }
    if (mincost <= k) {
      r = mid;
      continue;
    }
    mincost = INF;
    for (long long i = n - 1; i >= 0; --i) {
      long long ele = a[i] - mid, lcost, rcost = dpr[i];
      auto itr = upper_bound(a.rbegin(), a.rend(), ele, greater<long long>());
      if (itr == a.rend())
        lcost = 0;
      else {
        long long pos = a.rend() - itr - 1;
        lcost = dpl[pos] + (pos + 1) * (ele - a[pos]);
      }
      mincost = min(mincost, lcost + rcost);
    }
    if (mincost <= k) {
      r = mid;
      continue;
    }
    l = mid + 1;
  }
  cout << l << "\n";
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  { solve(); }
  return 0;
}
