#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
long long n, k, sum, c[500002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) cin >> c[i], sum += c[i];
  long long l = 0, r = sum / n + 1;
  while (l + 1 != r) {
    long long m = (l + r) / 2, sm = 0;
    for (long long i = 1; i <= n; i++)
      if (c[i] < m) sm += (m - c[i]);
    if (sm <= k)
      l = m;
    else
      r = m;
  }
  long long down = l;
  l = sum / n - 1, r = 1e9 + 1;
  while (l + 1 != r) {
    long long m = (l + r) / 2, sm = 0;
    for (long long i = 1; i <= n; i++)
      if (c[i] > m) sm += (c[i] - m);
    if (sm > k)
      l = m;
    else
      r = m;
  }
  long long up = r;
  if (up - down == 0 && sum % n != 0) up++;
  cout << up - down;
  return 0;
}
