#include <bits/stdc++.h>
using namespace std;
long long b[323567], c[323456], a[323456], tt, d[214564], e[216744], f[234563];
long long s, x, xx, m, y, r, n, t, k, har, l;
long long i, j, z;
queue<long long> w[223456];
string q, p, qq;
int main() {
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    s += a[i];
  }
  if (s <= k) {
    if (s % n == 0)
      cout << 0;
    else
      cout << 1;
    return 0;
  }
  l = 0;
  r = 1000000000;
  while (l < r) {
    m = (l + r) / 2;
    t = 0;
    for (i = 0; i < n; i++) {
      if (a[i] > m) t += a[i] - m;
    }
    if (t > k) {
      l = m + 1;
    } else
      r = m;
  }
  x = l;
  l = 0;
  r = 1000000000;
  while (l < r) {
    m = (l + r + 1) / 2;
    t = 0;
    for (i = 0; i < n; i++) {
      if (a[i] < m) t += m - a[i];
    }
    if (t > k) {
      r = m - 1;
    } else
      l = m;
  }
  if (l >= x) {
    if (s % n == 0)
      cout << 0;
    else
      cout << 1;
    return 0;
  }
  cout << x - l;
}
