#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9 + 10;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> c(n);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> c[i];
    sum += c[i];
  }
  long long low = -INF, high = INF;
  while (high - low > 1) {
    long long mid = (low + high) / 2, cost = 0;
    for (long long i = 0; i < n; i++) {
      cost += max(0LL, c[i] - mid);
    }
    if (cost <= k) {
      high = mid;
    } else {
      low = mid;
    }
  }
  long long ans = high;
  low = -INF, high = INF;
  while (high - low > 1) {
    long long mid = (low + high) / 2, cost = 0;
    for (long long i = 0; i < n; i++) {
      cost += max(0LL, mid - c[i]);
    }
    if (cost <= k) {
      low = mid;
    } else {
      high = mid;
    }
  }
  ans -= low;
  long long base = (sum % n == 0 ? 0 : 1);
  cout << max(ans, base);
  return 0;
}
