#include <bits/stdc++.h>
using namespace std;
const long long Nmax = 1e5 + 112;
const long long inf = 1e18;
long long n, k, a[Nmax], ps[Nmax], ans = inf;
bool check(long long D, long long U) {
  long long pos = lower_bound(a + 1, a + n + 1, D) - a - 1;
  long long S = D * pos - ps[pos];
  pos = upper_bound(a + 1, a + n + 1, U) - a;
  if (pos <= n) S += ps[n] - ps[pos - 1] - (n - pos + 1) * U;
  return S <= k;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = (long long)1; i <= (long long)n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (long long i = (long long)1; i <= (long long)n; ++i) {
    ps[i] = ps[i - 1] + a[i];
  }
  for (long long i = (long long)1; i <= (long long)n; ++i) {
    long long l = a[i], r = a[n], mid = (l + r) >> 1;
    while (l != mid && mid != r) {
      if (check(a[i], mid))
        r = mid;
      else
        l = mid;
      mid = (l + r) >> 1;
    }
    for (long long j = (long long)l; j <= (long long)r; ++j) {
      if (check(a[i], j)) ans = min(ans, j - a[i]);
    }
  }
  for (long long i = (long long)1; i <= (long long)n; ++i) {
    long long l = a[1], r = a[i], mid = (l + r) >> 1;
    while (l != mid && mid != r) {
      if (check(mid, a[i]))
        l = mid;
      else
        r = mid;
      mid = (l + r) >> 1;
    }
    for (long long j = (long long)l; j <= (long long)r; ++j) {
      if (check(j, a[i])) ans = min(ans, a[i] - j);
    }
  }
  cout << ans;
}
