#include <bits/stdc++.h>
using namespace std;
long long c[500011];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    sum += c[i];
  }
  sort(c, c + n);
  int lo = 0;
  int hi = c[n - 1];
  int mid;
  while (hi - lo > 1) {
    mid = (hi + lo) / 2;
    long long second = 0;
    for (int i = 0; i < n; i++) {
      second += max(0LL, c[i] - mid);
    }
    if (second <= k)
      hi = mid;
    else
      lo = mid;
  }
  long long ma = hi;
  lo = c[0];
  hi = ma + 1;
  while (hi - lo > 1) {
    mid = (hi + lo) / 2;
    long long second = 0;
    for (int i = 0; i < n; i++) {
      second += max(0LL, mid - c[i]);
    }
    if (second <= k)
      lo = mid;
    else
      hi = mid;
  }
  if (ma == lo and sum % n == 0) {
    cout << 0;
    return 0;
  }
  cout << max(1LL, ma - lo);
}
