#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
int n, k, a[maxn];
long long sum = 0;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
  sort(a + 1, a + 1 + n);
  int l1 = sum / n, r1 = (sum + n - 1) / n;
  int l = 0, r = l1, ansl = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    long long need = 0;
    for (int i = 1; i <= n; i++)
      if (a[i] <= mid) need += mid - a[i];
    if (need <= k)
      ansl = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  l = r1, r = 1e9;
  int ansr = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    long long need = 0;
    for (int i = 1; i <= n; i++)
      if (a[i] > mid) need += a[i] - mid;
    if (need <= k)
      ansr = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ansr - ansl << endl;
}
