#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int inf = 1e9;
int n, k;
int c[N];
long long tot;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    tot += c[i];
  }
  int p = tot / n, q = (tot + n - 1) / n;
  int l = 1, r = tot / n;
  int low, high;
  while (l <= r) {
    int mid = (l + r) >> 1;
    long long cnt = 0;
    for (int i = 0; i < n; ++i)
      if (c[i] < mid) cnt += mid - c[i];
    if (cnt <= k) {
      low = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = q, r = inf;
  while (l <= r) {
    int mid = (l + r) >> 1;
    long long cnt = 0;
    for (int i = 0; i < n; ++i)
      if (c[i] > mid) cnt += c[i] - mid;
    if (cnt <= k) {
      high = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << high - low << endl;
  return 0;
}
