#include <bits/stdc++.h>
using namespace std;
double const EPS = 1e-9, PI = acos(-1);
const int N = 5e5 + 9, M = 2e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const long long inf = 1e18;
long long arr[N], n, k;
bool check(long long mid, bool opt) {
  long long totalL = 0, totalR = 0;
  for (int i = 0; i < n; ++i) {
    totalL += max(0ll, mid - arr[i]);
    totalR += max(0ll, arr[i] - mid);
  }
  if (opt) return totalL <= k && totalL <= totalR;
  return totalR <= k && totalR <= totalL;
}
int main() {
  cout << fixed << setprecision(0), ios::sync_with_stdio(false),
      cin.tie(nullptr), cout.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  long long start = 1, end = 1e9, mnVal, mxVal;
  while (start <= end) {
    long long mid = (start) + (end - start) / 2;
    if (check(mid, 1))
      mnVal = mid, start = mid + 1;
    else
      end = mid - 1;
  }
  start = 1, end = 1e9;
  while (start <= end) {
    long long mid = (start) + (end - start) / 2;
    if (check(mid, 0))
      mxVal = mid, end = mid - 1;
    else
      start = mid + 1;
  }
  cout << mxVal - mnVal;
  return 0;
}
