#include <bits/stdc++.h>
using namespace std;
int N;
long long K;
long long A[100005], S1[100005], S2[100005];
long long P1[100005], P2[100005];
inline void solve(long long R, long long S[], long long P[], long long& ansr) {
  int p = lower_bound(S + 1, S + N, R) - S - 1;
  ansr = (R - S[p]) / (p + 1) + P[p];
}
inline long long getAns(long long use) {
  long long r1, r2;
  solve(use, S1, P1, r1);
  solve(K - use, S2, P2, r2);
  r1 = min(A[N], A[1] + r1);
  r2 = max(A[1], A[N] - r2);
  if (r1 > r2) return 0;
  return r2 - r1;
}
int main() {
  scanf("%d %lld", &N, &K);
  for (int i = 1; i <= N; ++i) scanf("%lld", A + i);
  sort(A + 1, A + N + 1);
  for (int i = 1; i < N; ++i) {
    S1[i] = S1[i - 1] + (A[i + 1] - A[i]) * i;
    P1[i] = A[i + 1] - A[1];
  }
  for (int i = N - 1; i >= 1; --i) {
    S2[N - i] = S2[N - i - 1] + (A[i + 1] - A[i]) * (N - i);
    P2[N - i] = A[N] - A[i];
  }
  set<long long> rem;
  long long val = 0;
  rem.insert(0);
  for (int i = 2; i <= N; ++i) {
    val += (A[i] - A[i - 1]) * (i - 1);
    if (val > K) break;
    rem.insert(val);
  }
  val = 0;
  rem.insert(K);
  for (int i = N - 1; i >= 1; --i) {
    val += (A[i + 1] - A[i]) * (N - i);
    if (val > K) break;
    rem.insert(K - val);
  }
  long long L = 0;
  long long ans = 100000000000000000LL;
  rem.erase(0);
  rem.insert(K + 1);
  for (auto R : rem) {
    ans = min(ans, getAns(L));
    ans = min(ans, getAns(R - 1));
    L = R;
  }
  printf("%lld\n", ans);
  return 0;
}
