#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int a[maxn], n, k;
long long sum;
long long judge1(int m) {
  long long ans = 0;
  for (int i = 1; a[i] < m && i <= n; i++) {
    ans += m - a[i];
  }
  return ans;
}
long long judge2(int m) {
  long long ans = 0;
  for (int i = n; a[i] > m && i >= 1; i--) {
    ans += a[i] - m;
  }
  return ans;
}
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 + n + 1);
  int l = a[1], r = a[n], poorest = a[1];
  while (l <= r) {
    int mid = (l + r) >> 1;
    long long p = judge1(mid);
    if (p <= k) {
      poorest = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = a[1];
  r = a[n];
  int richest = a[n];
  while (l <= r) {
    int mid = (l + r) >> 1;
    long long p = judge2(mid);
    if (p <= k) {
      richest = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  if (poorest < richest)
    printf("%d\n", richest - poorest);
  else {
    if (sum % n == 0)
      printf("0\n");
    else
      printf("1\n");
  }
  return 0;
}
