#include <bits/stdc++.h>
using namespace std;
int n;
long long coins[500005], k;
bool isPossible(int x) {
  int i;
  long long total = 0;
  for (i = n - 1; i >= 0; i--) {
    if (coins[i] > x)
      total += (coins[i] - x);
    else
      break;
  }
  if (total > k) return false;
  for (i = 0; i < n; i++) {
    if (coins[i] < x)
      total -= (x - coins[i]);
    else
      break;
  }
  if (total > 0) return false;
  return true;
}
int main() {
  int x;
  long long totalDistributing, required, canBeUp, i, hi, lo, mid,
      richestPersonCoin, poorestPersonCoin;
  scanf("%d %d", &n, &x);
  k = x;
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    coins[i] = x;
  }
  sort(coins, coins + n);
  lo = coins[0];
  hi = coins[n - 1];
  while (hi > lo) {
    mid = (lo + hi) / 2;
    if (isPossible(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  richestPersonCoin = lo;
  totalDistributing = 0;
  for (i = n - 1; i >= 0; i--) {
    if (coins[i] > richestPersonCoin) {
      totalDistributing += (coins[i] - richestPersonCoin);
      coins[i] = richestPersonCoin;
    } else
      break;
  }
  while (i >= 0 && coins[i] == richestPersonCoin) i--;
  i++;
  while (totalDistributing < k && i < n - 1) {
    totalDistributing++;
    coins[i]--;
    i++;
  }
  for (i = 1; i < n; i++) {
    required = coins[i] - coins[i - 1];
    if (required * i <= totalDistributing)
      totalDistributing -= required * i;
    else
      break;
  }
  canBeUp = totalDistributing / i;
  poorestPersonCoin = coins[i - 1] + canBeUp;
  cout << richestPersonCoin - poorestPersonCoin << endl;
  return 0;
}
