#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-10;
const long long MOD = 1000000007ll;
const long long mod1 = 1000000009ll;
const long long mod2 = 1100000009ll;
int INF = (int)1e9 + 5;
long long INFINF = (long long)1e18;
long long coins[500010];
int main() {
  long long n, k, sum;
  scanf("%lld", &n);
  scanf("%lld", &k);
  sum = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &coins[i]);
    sum += coins[i];
  }
  sort(coins, coins + n);
  long long p, x;
  p = 1;
  x = k;
  while (p < n && (coins[p] - coins[p - 1]) * p <= x) {
    x -= (coins[p] - coins[p - 1]) * p;
    p++;
  }
  long long lowest = coins[p - 1] + x / p;
  p = 1;
  x = k;
  while (p < n && (coins[n - p] - coins[n - p - 1]) * p <= x) {
    x -= (coins[n - p] - coins[n - p - 1]) * p;
    p++;
  }
  long long highest = coins[n - p] - x / p;
  if (highest <= lowest)
    if (sum % n == 0)
      cout << "0" << endl;
    else
      cout << "1" << endl;
  else
    cout << highest - lowest << endl;
  return 0;
}
