#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100005], s[100005], ans = 9223372036854775807;
long long calc(int m) { return s[n] - s[m - 1] - (n - m + 1) * a[m]; }
long long solve(long long low) {
  int pos = lower_bound(a + 1, a + n + 1, low) - a - 1;
  long long rst = k - (pos * low - s[pos]);
  if (rst < 0) return 9223372036854775807;
  long long l = pos, r = n, m;
  while (l < r - 3) {
    m = (l + r) >> 1;
    if (calc(m) > rst)
      l = m + 1;
    else
      r = m;
  }
  int up = l;
  for (up = l; up <= r; up++)
    if (calc(up) <= rst) break;
  return ((0) > (a[up] - (rst - calc(up)) / (n - up + 1) - low)
              ? (0)
              : (a[up] - (rst - calc(up)) / (n - up + 1) - low));
}
int main() {
  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++) s[i] = s[i - 1] + a[i];
  int l = a[1], r = a[n], ml, mr;
  while (l < r - 6) {
    ml = l + (r - l) / 3, mr = r - (r - l) / 3;
    if (solve(ml) > solve(mr))
      l = ml;
    else
      r = mr;
  }
  for (int i = l; i <= r; i++) ans = min(ans, solve(i));
  cout << ans;
  return 0;
}
