#include <bits/stdc++.h>
using namespace std;
int input() {
  int res = 0;
  char c = ' ';
  while (c < '0') c = getchar();
  while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
  return res;
}
const int N = 5e5 + 1;
long long n, k, sum, a[N], p[N], s[N];
bool f(long long x) {
  int i = lower_bound(a, a + n, x) - a - 1;
  return (i < 0 || x * (i + 1) - p[i] <= k);
}
bool g(long long x) {
  int i = lower_bound(a, a + n, x) - a;
  return (i >= n || s[i] - x * (n - i) <= k);
}
int main() {
  n = input(), k = input();
  for (int i = 0; i < n; ++i) a[i] = input();
  sort(a, a + n);
  for (int i = 0; i < n; ++i) p[i] = sum += a[i];
  long long l = 1, r = sum / n + 1;
  while (l < r) {
    long long m = (l + r) >> 1;
    if (f(m))
      l = m + 1;
    else
      r = m;
  }
  sum = 0;
  for (int i = n - 1; i >= 0; --i) s[i] = sum += a[i];
  long long x = --l, y;
  l = sum / n, r = 1e9;
  while (l < r) {
    long long m = (l + r) >> 1;
    if (g(m))
      r = m;
    else
      l = m + 1;
  }
  y = l;
  if (x == y && sum % n) ++y;
  cout << y - x;
}
