#include <bits/stdc++.h>
using namespace std;
vector<int> a;
long long mx = -1e9 - 10, mn = 1e9 + 10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  long long sm = 0;
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sm += a[i];
    if (a[i] > mx) mx = a[i];
    if (a[i] < mn) mn = a[i];
  }
  int l = (sm + n - 1) / n, r = mx;
  int res1, res2;
  while (l <= r) {
    int mid = ((l + r) >> 1);
    long long s = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > mid) {
        s += a[i] - mid;
      }
    }
    if (s <= k) {
      res1 = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  l = mn, r = sm / n;
  while (l <= r) {
    int mid = ((l + r) >> 1);
    long long s = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] < mid) {
        s += mid - a[i];
      }
    }
    if (s <= k) {
      res2 = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << res1 - res2 << endl;
}
