#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[100100];
long long go(long long mini, long long sum) {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > mini + sum)
      res += a[i] - (mini + sum);
    else if (a[i] < mini)
      res += mini - a[i];
  }
  return res;
}
long long calck(long long diff) {
  long long l = 0, r = 1e14;
  while (r - l > 4) {
    long long m1 = (l + r) / 2;
    long long m2 = (l + r) / 2 + 1;
    if (go(m1, diff) < go(m2, diff))
      r = m2;
    else
      l = m1;
  }
  long long cnt = 1e18;
  for (long long i = l; i <= r; i++) cnt = min(cnt, go(i, diff));
  return cnt;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long l = 0, r = 1e9;
  while (l != r) {
    long long mid = (l + r) / 2;
    if (calck(mid) <= k)
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}
