#include <bits/stdc++.h>
using namespace std;
const long long M = 1e6;
long long a[M];
long long n, k;
bool check_min(long long x) {
  long long p = k;
  for (long long i = 0; i < n; i++) {
    if (a[i] > x) break;
    p = p - (x - a[i]);
  }
  if (p >= 0)
    return 1;
  else
    return 0;
}
bool check_max(long long x) {
  long long p = k;
  for (long long i = 0; i < n; i++) {
    if (a[i] >= x) p = p - (a[i] - x);
  }
  if (p >= 0)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%lld%lld", &n, &k);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  sort(a, a + n);
  long long lm = sum / n;
  long long rm = (sum + n - 1) / n;
  long long l, r;
  l = 0, r = lm;
  while (r >= l) {
    long long mid = (l + r) >> 1;
    if (check_min(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  long long mini = r, mac;
  l = rm, r = a[n - 1];
  while (r >= l) {
    long long mid = (l + r) >> 1;
    if (check_max(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  mac = l;
  printf("%lld\n", mac - mini);
  return 0;
}
