#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, k, a[N], res;
long long s[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i];
  int l = 0, r = 1e9;
  while (l < r) {
    int m = (l + r + 1) >> 1;
    int p = lower_bound(a + 1, a + 1 + n, m) - a;
    long long s1 = s[n] - s[p - 1];
    long long s2 = s[p - 1];
    if (1LL * (p - 1) * m - s2 <= s1 - 1LL * m * (n - p + 1) &&
        1LL * (p - 1) * m - s2 <= k)
      l = m;
    else
      r = m - 1;
  }
  res -= l;
  l = 0, r = 1e9;
  while (l < r) {
    int m = (l + r) >> 1;
    int p = lower_bound(a + 1, a + 1 + n, m) - a;
    long long s1 = s[n] - s[p - 1];
    long long s2 = s[p - 1];
    if (s1 - 1LL * m * (n - p + 1) <= k &&
        1LL * (p - 1) * m - s2 >= s1 - 1LL * m * (n - p + 1))
      r = m;
    else
      l = m + 1;
  }
  res += l;
  cout << res;
}
