#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  sort(c.begin(), c.end());
  long long max_c = -1, sum = 0;
  for (int i = n - 1; i > 0; --i) {
    if (sum + (n - i) * (c[i] - c[i - 1]) > k) {
      max_c = c[i] - (k - sum) / (n - i);
      break;
    } else {
      sum += (n - i) * (c[i] - c[i - 1]);
    }
  }
  long long min_c = 0;
  sum = 0;
  for (int i = 1; i < n; ++i) {
    if (sum + i * (c[i] - c[i - 1]) > k) {
      min_c = c[i - 1] + (k - sum) / i;
      break;
    } else {
      sum += i * (c[i] - c[i - 1]);
    }
  }
  if (max_c <= min_c) {
    cout << (accumulate(c.begin(), c.end(), 0LL) % n == 0 ? 0 : 1) << endl;
  } else {
    cout << max_c - min_c << endl;
  }
}
