#include <bits/stdc++.h>
using namespace std;
template <typename T>
int Max(T begin, T end) {
  int ret = *begin;
  while (begin != end) {
    ret = max(ret, *begin);
    ++begin;
  }
  return ret;
}
template <typename T>
int Min(T begin, T end) {
  int ret = *begin;
  while (begin < end) {
    ret = min(ret, *begin);
    ++begin;
  }
  return ret;
}
int GetLower(const vector<int>& c, int k) {
  int l = Min(c.begin(), c.end()), r = Max(c.begin(), c.end()) + 1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    long long s = 0;
    for (auto x : c)
      if (x < m) s += m - x;
    if (s <= k) {
      l = m;
    } else {
      r = m;
    }
  }
  return l;
}
int GetUpper(const vector<int>& c, int k) {
  int l = Min(c.begin(), c.end()) - 1, r = Max(c.begin(), c.end());
  while (r - l > 1) {
    int m = (l + r) / 2;
    long long s = 0;
    for (auto x : c)
      if (x > m) s += x - m;
    if (s <= k) {
      r = m;
    } else {
      l = m;
    }
  }
  return r;
}
bool CanBeZero(const vector<int>& c) {
  long long s = 0;
  for (auto x : c) s += x;
  return s % c.size() == 0;
}
int Solve(const vector<int>& c, int k) {
  int lower = GetLower(c, k);
  int upper = GetUpper(c, k);
  int answer = upper - lower;
  if (answer <= 0) answer = 0;
  return answer == 0 && !CanBeZero(c) ? 1 : answer;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> c(n);
  for (int i = 0; i < (int)c.size(); ++i) cin >> c[i];
  cout << Solve(c, k) << endl;
  return 0;
}
