#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
long long m, n, a[N], sum, l, r, mid, k, ave, t;
bool flag;
bool judge(long long x) {
  sum = 0;
  if (!flag) {
    for (int i = 1; i <= n; ++i) {
      if (a[i] < x) sum += x - a[i];
    }
    if (sum <= k) return true;
    return false;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] > x) sum += a[i] - x;
  }
  if (sum <= k) return true;
  return false;
}
int main() {
  scanf("%I64d %I64d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
    ave += a[i];
  }
  l = 1, r = ave / n;
  while (l <= r) {
    mid = l + ((r - l) >> 1);
    if (judge(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  t = l - 1;
  flag = 1;
  l = (ave - 1) / n + 1, r = 1e10;
  while (l <= r) {
    mid = l + ((r - l) >> 1);
    if (judge(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%I64d\n", r + 1 - t);
}
