#include <bits/stdc++.h>
using namespace std;
const long long mx = 10000001;
const long long mod = 1000000007;
const long long inf = 0x3f3f3f3f;
void solve();
int main() {
  solve();
  return 0;
}
long long n, k, tot, m, a[500005];
void solve() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), tot += a[i], m = max(m, a[i]);
  int s = 0, t = tot / n;
  while (s != t) {
    int mid = (s + t) / 2 + 1;
    long long sum = 0;
    for (int i = 1; i <= n; i++)
      if (a[i] < mid) sum += mid - a[i];
    if (sum > k)
      t = mid - 1;
    else
      s = mid;
  }
  int ans1 = s;
  s = (tot + n - 1) / n, t = m;
  while (s != t) {
    int mid = (s + t) / 2;
    long long sum = 0;
    for (int i = 1; i <= n; i++)
      if (a[i] > mid) sum += a[i] - mid;
    if (sum > k)
      s = mid + 1;
    else
      t = mid;
  }
  int ans2 = s;
  cout << ans2 - ans1 << endl;
}
