#include <bits/stdc++.h>
using namespace std;
struct __STARTER_OF_PROGRAM__ {
  __STARTER_OF_PROGRAM__() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(12);
  }
} __starter_of_program__;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using min_queue = priority_queue<T, vector<T>, greater<T> >;
template <typename T>
using max_queue = priority_queue<T>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
static uniform_int_distribution<int> __disint__;
inline int randint(void) { return __disint__(gen); }
inline int randint(int l, int r) { return __disint__(gen) % (r - l + 1) + l; }
template <typename T>
inline void reinit(T &t) {
  t.~T();
  new (&t) T();
}
template <typename T>
inline T chmax(T &x, T y) {
  return x = max(x, y);
}
template <typename T>
inline T chmin(T &x, T y) {
  return x = min(x, y);
}
template <typename T>
inline T chmax(T &x, initializer_list<T> i) {
  return x = max(x, max(i));
}
template <typename T>
inline T chmin(T &x, initializer_list<T> i) {
  return x = min(x, min(i));
}
inline void read() {}
inline void write() {}
template <typename T>
inline void read(T &x) {
  cin >> x;
}
template <typename T>
inline void write(const T &x) {
  cout << x;
}
template <typename T, typename U>
inline void write(const pair<T, U> &x) {
  write(x.first), cout.put(' '), write(x.second);
}
template <typename T, typename U>
inline void read(pair<T, U> &x) {
  read(x.first), read(x.second);
}
template <typename T, typename... Ts>
inline void read(T &x, Ts &...y) {
  read(x), read(y...);
}
template <typename T, typename... Ts>
inline void write(const T &x, const Ts &...y) {
  write(x), (sizeof...(y) && (cout.put(' '), 0)), write(y...);
}
template <typename It>
inline void _write(It a, It b) {
  register char flag = 0;
  while (a != b) {
    flag && (cout.put(' '), 0);
    write(*a++), flag = 1;
  }
}
const int mod1 = 1000000007, mod2 = 998244353, mod3 = 1000000009;
const double EPS = 1e-9, PI = acos(-1.0), _E_ = exp(1.0);
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;
static const int Maxn = 100005;
int n;
ll k, a[Maxn], prvsum[Maxn], sufsum[Maxn];
inline bool check(ll d) {
  vector<pair<ll, ll> > v;
  for (register int i = (1); i <= (n); ++i) {
    v.push_back({a[i] - d, a[i]});
    v.push_back({a[i], a[i] + d});
  }
  for (auto &x : v) {
    ll l = x.first, r = x.second;
    int c = lower_bound(a + 1, a + n + 1, r, greater<ll>()) - a - 1;
    ll prv = max(prvsum[c] - c * r, 0LL);
    c = upper_bound(a + 1, a + n + 1, l, greater<ll>()) - a;
    ll suf = max((n - c + 1) * l - sufsum[c], 0LL);
    if (prv + suf <= k) return true;
  }
  return false;
}
signed main(int argc, const char *argv[]) {
  read(n, k);
  for (register int i = (1); i <= (n); ++i) read(a[i]);
  sort(a + 1, a + n + 1, greater<ll>());
  for (register int i = (1); i <= (n); ++i) prvsum[i] = prvsum[i - 1] + a[i];
  for (register int i = (n); i; --i) sufsum[i] = sufsum[i + 1] + a[i];
  ll l = 0, r = a[1] - a[n], ans = a[1] - a[n];
  while (l <= r) {
    ll mid = l + r >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  (write(ans), cout.put('\n'), 0);
  return 0;
}
