#include <bits/stdc++.h>
using namespace std;
long long A[500001];
int n;
long long gede(long long kiri, long long kanan) {
  if (kiri < kanan)
    return kanan;
  else
    return kiri;
}
int main() {
  int k;
  long long total = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &A[i]);
    total += A[i];
  }
  long long maks, mini, l = 0, r = 1000000001;
  while (l <= r) {
    long long tgh = (l + r) / 2;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      sum += gede(0, tgh - A[i]);
    }
    if (sum <= k)
      l = tgh + 1;
    else
      r = tgh - 1;
  }
  mini = r;
  l = 0, r = 1000000001;
  while (l <= r) {
    long long tgh = (l + r) / 2;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      sum += gede((long long)0, A[i] - tgh);
    }
    if (sum <= k)
      r = tgh - 1;
    else
      l = tgh + 1;
  }
  maks = l;
  if (mini < maks)
    cout << maks - mini << "\n";
  else {
    if (total % n == 0)
      cout << "0\n";
    else
      cout << "1\n";
  }
}
