#include <bits/stdc++.h>
int n, k;
long long c[500010];
int s, e, v;
int max, min;
long long avg;
bool max_able(int x) {
  int i;
  long long r = 0;
  for (i = 1; i <= n; i++)
    if (c[i] > x) r += c[i] - x;
  return r <= k;
}
bool min_able(int x) {
  int i;
  long long r = 0;
  for (i = 1; i <= n; i++)
    if (c[i] < x) r += x - c[i];
  return r <= k;
}
int main() {
  int i;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%I64d", &c[i]);
  s = 1;
  e = 0x40000000;
  while (s < e) {
    v = (s + e) / 2;
    if (max_able(v))
      e = v;
    else
      s = v + 1;
  }
  max = s;
  s = 1;
  e = 0x40000000;
  while (s < e) {
    v = (s + e) / 2 + 1;
    if (min_able(v))
      s = v;
    else
      e = v - 1;
  }
  min = s;
  if (max > min) {
    printf("%d", max - min);
    return 0;
  }
  for (i = 1; i <= n; i++) avg += c[i];
  if (avg / n * n == avg)
    printf("0");
  else
    printf("1");
}
