#include <bits/stdc++.h>
using namespace std;
const int maxn = 500009;
int a[maxn], n, K, l, mid, r, ansL, ansR;
long long total;
bool check1(int x) {
  int tot = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] < x) {
      tot += x - a[i];
      if (tot > K) return false;
    }
  return true;
}
bool check2(int x) {
  int tot = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] > x) {
      tot += a[i] - x;
      if (tot > K) return false;
    }
  return true;
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    total += a[i];
  }
  l = 1;
  r = 1e9;
  while (l < r) {
    mid = (l + r + 1) >> 1;
    if (check1(mid))
      l = mid;
    else
      r = mid - 1;
  }
  ansL = l;
  l = 1;
  r = 1e9;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check2(mid))
      r = mid;
    else
      l = mid + 1;
  }
  ansR = l;
  if (ansR - ansL >= 1)
    printf("%d\n", ansR - ansL);
  else
    printf("%d\n", 1 - (total % n == 0));
  return 0;
}
