#include <bits/stdc++.h>
using namespace std;
int n, a[100000 + 3], sortedA[100000 + 3], answer;
long long int k, prefixSum[100000 + 3];
pair<int, long long int> statsSmaller(int h) {
  int pos = lower_bound(sortedA + 1, sortedA + n + 1, h) - sortedA;
  return make_pair(pos - 1, prefixSum[pos - 1]);
}
pair<int, long long int> statsLarger(int h) {
  int pos = upper_bound(sortedA + 1, sortedA + n + 1, h) - sortedA;
  return make_pair(n - pos + 1, prefixSum[n] - prefixSum[pos - 1]);
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sortedA[i] = a[i];
  }
  answer = 2e9;
  sort(sortedA + 1, sortedA + n + 1);
  prefixSum[0] = 0;
  for (int i = 1; i <= n; i++) prefixSum[i] = prefixSum[i - 1] + sortedA[i];
  for (int i = 1; i <= n; i++) {
    long long int opsLeft = k;
    pair<int, long long int> statSmall = statsSmaller(a[i]);
    opsLeft -= ((long long int)a[i] * statSmall.first - statSmall.second);
    if (opsLeft <= 0) continue;
    int lo = a[i], hi = 1e9, mid;
    while (hi >= lo) {
      mid = (lo + hi) / 2;
      pair<int, long long int> statLarge = statsLarger(mid);
      long long int cost =
          statLarge.second - (long long int)mid * statLarge.first;
      if (cost <= opsLeft)
        hi = mid - 1;
      else
        lo = mid + 1;
    }
    answer = min(answer, lo - a[i]);
  }
  for (int i = 1; i <= n; i++) {
    long long int opsLeft = k;
    pair<int, long long int> statLarge = statsLarger(a[i]);
    opsLeft -= (statLarge.second - (long long int)a[i] * statLarge.first);
    if (opsLeft <= 0) continue;
    int lo = 0, hi = a[i], mid;
    while (hi >= lo) {
      mid = (lo + hi) / 2;
      pair<int, long long int> statSmall = statsSmaller(mid);
      long long int cost =
          (long long int)mid * statSmall.first - statSmall.second;
      if (cost <= opsLeft)
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    answer = min(answer, a[i] - hi);
  }
  printf("%d\n", answer);
}
