#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> ar(n);
  for (long long i = 0; i < n; i++) cin >> ar[i];
  sort(ar.begin(), ar.end());
  vector<long long> left_cost(n), right_cost(n);
  left_cost[0] = 0;
  for (long long i = 1; i < n; i++) {
    left_cost[i] = left_cost[i - 1] + (ar[i] - ar[i - 1]) * (i);
  }
  right_cost[n - 1] = 0;
  for (long long i = n - 2; i >= 0; i--) {
    right_cost[i] = right_cost[i + 1] + (ar[i + 1] - ar[i]) * (n - i - 1);
  }
  long long l = 0, r = 0;
  long long fans = 2e9;
  long long cur_cost = left_cost[l] + right_cost[l];
  while (l < n) {
    while (cur_cost > k and r + 1 < n) {
      r++;
      cur_cost = left_cost[l] + right_cost[r];
    }
    if (cur_cost <= k) {
      long long rk = k - cur_cost;
      long long cr = n - r;
      long long dif = ar[r] - ar[l] - rk / cr;
      fans = min(fans, dif);
    }
    l++;
    cur_cost = left_cost[l] + right_cost[r];
  }
  l = n - 1, r = n - 1;
  ;
  while (r >= 0) {
    cur_cost = left_cost[l] + right_cost[r];
    while (cur_cost > k and l - 1 >= 0) {
      l--;
      cur_cost = left_cost[l] + right_cost[r];
    }
    if (cur_cost <= k) {
      long long rk = k - cur_cost;
      long long cl = l + 1;
      long long dif = ar[r] - ar[l] - rk / cl;
      fans = min(fans, dif);
    }
    r--;
  }
  if (fans < 0) fans = 0;
  cout << fans << "\n";
  return 0;
}
