#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
long long f(int a[], int l, int r) {
  long long m = 0;
  for (int i = 0; i < n; i++)
    if (a[i] < l)
      m += l - a[i];
    else if (a[i] > r)
      m += a[i] - r;
  return m;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  cin >> n >> k;
  int a[n];
  for (int& i : a) cin >> i;
  int l = 0, r = 1e9;
  while (l <= r) {
    int m = (l + r) / 2;
    int lt = 0, rt = 1e9 - m;
    while (rt - lt > 1) {
      int mt = (lt + rt) / 2;
      if (f(a, mt, mt + m) < f(a, mt + 1, mt + 1 + m))
        rt = mt;
      else
        lt = mt;
    }
    if (f(a, rt, rt + m) <= k)
      r = m - 1;
    else
      l = m + 1;
  }
  cout << l << "\n";
}
