#include <bits/stdc++.h>
using namespace std;
long long int n, k;
vector<long long int> a;
long long int robinhood() {
  long long int s = 0;
  long long int e = 1e9 + 100;
  long long int min = 0, max = 0;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) ans += a[i];
  while (s <= e) {
    long long int mid = (s + e) >> 1;
    long long int sum = 0;
    for (long long int i = 0; i < n; i++) {
      if (mid - a[i] >= 0) sum += mid - a[i];
    }
    if (sum <= k) {
      min = mid;
      s = mid + 1;
    } else
      e = mid - 1;
  }
  s = 0;
  e = 1e9 + 100;
  while (s <= e) {
    long long int mid = (s + e) >> 1;
    long long int sum = 0;
    for (long long int i = 0; i < n; i++) {
      if (a[i] - mid >= 0) sum += a[i] - mid;
    }
    if (sum <= k) {
      max = mid;
      e = mid - 1;
    } else
      s = mid + 1;
  }
  return max - min > 0 ? max - min : (ans % n == 0 ? 0 : 1);
}
int32_t main() {
  cin >> n >> k;
  a.resize(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  cout << robinhood();
  return 0;
}
