#include <bits/stdc++.h>
using namespace std;
const long long N = 500001;
long long a[N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  long long sum = 0;
  for (long long i = 0; i < n; i++) cin >> a[i], sum += a[i];
  sort(a, a + n);
  long long l = a[0], r = a[n - 1];
  while (r - l > 1) {
    long long m = (l + r) / 2;
    long long excess = 0;
    for (long long i = n - 1; i >= 0; i--) {
      if (a[i] < m) break;
      excess += a[i] - m;
    }
    if (excess > k)
      l = m;
    else
      r = m;
  }
  long long maxm = r;
  l = a[0], r = a[n - 1];
  while (r - l > 1) {
    long long m = (l + r) / 2;
    long long excess = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] > m) break;
      excess += m - a[i];
    }
    if (excess > k)
      r = m;
    else
      l = m;
  }
  long long minm = l;
  if (minm >= maxm) {
    cout << !!(sum % n);
  } else
    cout << maxm - minm;
}
