#include <bits/stdc++.h>
using namespace std;
const int oo = 2000000000;
const int maxn = 500005;
int n;
long long k, ansl, ansr, l = -1, r = -1;
long long c[maxn];
inline int read() {
  int x = 0;
  bool flag = false;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') flag = true;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
bool check1(long long limit) {
  long long num = 0;
  for (int i = 1; i <= n; i++)
    if (c[i] < limit) num += limit - c[i];
  return num <= k;
}
bool check2(long long limit) {
  long long num = 0;
  for (int i = 1; i <= n; i++)
    if (c[i] > limit) num += c[i] - limit;
  return num <= k;
}
bool cheat() {
  long long sum = 0, total, num = 0;
  for (int i = 1; i <= n; i++) sum += c[i];
  total = sum, sum /= n;
  for (int i = 1; i <= n; i++)
    if (sum < c[i]) num += c[i] - sum;
  if (num > k) return false;
  if (total == sum * n)
    printf("0\n");
  else
    printf("1\n");
  return true;
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) {
    c[i] = read();
    if (c[i] < l || l == -1) l = c[i];
    if (c[i] > r || r == -1) r = c[i];
  }
  if (cheat()) return 0;
  l--, r++;
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    if (check1(mid))
      l = ansl = mid;
    else
      r = mid;
  }
  l = r = -1;
  for (int i = 1; i <= n; i++) {
    if (c[i] < l || l == -1) l = c[i];
    if (c[i] > r || r == -1) r = c[i];
  }
  l--, r++;
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    if (check2(mid))
      r = ansr = mid;
    else
      l = mid;
  }
  cout << ansr - ansl << endl;
  return 0;
}
