#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)5E5 + 10;
const int INF = (int)1E9 + 10;
int n, k;
int a[MAX];
int vmin, vmax;
int main() {
  scanf("%d%d", &n, &k);
  if (n == 1) {
    printf("0");
    return 0;
  }
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  long long sum;
  sum = 0;
  for (int i = n - 2; i >= 0; i--) {
    sum += (long long)(a[i + 1] - a[i]) * (n - i - 1);
    if (sum >= k) {
      int t = k - (sum - (long long)(a[i + 1] - a[i]) * (n - i - 1));
      vmax = a[i + 1] - t / (n - i - 1);
      break;
    }
    if (i == 0) vmax = a[i];
  }
  sum = 0;
  for (int i = 1; i < n; i++) {
    sum += (long long)(a[i] - a[i - 1]) * i;
    if (sum >= k) {
      int t = k - (sum - (long long)(a[i] - a[i - 1]) * i);
      vmin = a[i - 1] + t / i;
      break;
    }
    if (i == n - 1) vmin = a[i];
  }
  sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  if (vmin < vmax)
    printf("%d", vmax - vmin);
  else
    printf("%d", 1 - (sum % n == 0));
}
