#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const long long MX = 1e9 + 1;
int n;
long long k;
long long a[N], p[N];
long long get(int l, int r) { return p[r] - p[l - 1]; }
bool check(long long l, long long r) {
  int lo = 0, hi = n + 1;
  while (lo + 1 < hi) {
    int mid = (lo + hi) / 2;
    if (a[mid] < l)
      lo = mid;
    else
      hi = mid;
  }
  long long sum = lo * l - get(1, lo);
  lo = 0;
  hi = n + 1;
  while (lo + 1 < hi) {
    int mid = (lo + hi) / 2;
    if (a[mid] > r)
      hi = mid;
    else
      lo = mid;
  }
  sum += get(hi, n) - (n + 1 - hi) * r;
  return sum <= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) p[i] = a[i] + p[i - 1];
  long long ans = MX;
  for (int i = 1; i <= n; ++i) {
    if (i * a[i] - get(1, i) > k) break;
    long long lo = a[i] - 1, hi = MX;
    while (lo + 1 < hi) {
      long long mid = (lo + hi) / 2;
      if (check(a[i], mid))
        hi = mid;
      else
        lo = mid;
    }
    ans = min(ans, hi - a[i]);
  }
  for (int i = n; i >= 1; --i) {
    if (get(i, n) - (n + 1 - i) * a[i] > k) break;
    long long lo = 0, hi = a[i] + 1;
    while (lo + 1 < hi) {
      long long mid = (lo + hi) / 2;
      if (check(mid, a[i]))
        lo = mid;
      else
        hi = mid;
    }
    ans = min(ans, a[i] - lo);
  }
  cout << ans << '\n';
}
