#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cnt;
vector<long long> pos;
long long n, k;
long long p1, p2, p3, p4;
long long l, r;
long long res;
clock_t tIn, tEn;
void calcTemp() {
  clock_t tEn = clock();
  double temp = (tEn - tIn) / (CLOCKS_PER_SEC / 1000);
  cout << temp << endl;
}
int calcL() {
  if (k >= cnt[p1]) {
    long long t = k / cnt[p1];
    if (t >= p2 - p1) {
      res = p4 - p2;
      l++;
      cnt[p2] += cnt[p1];
      k -= cnt[p1] * (p2 - p1);
      cnt[p1] = 0;
    } else {
      res -= t;
      cout << res << endl;
      return 0;
    }
  } else {
    cout << res << endl;
    return 0;
  }
  return 1;
}
int calcR() {
  if (k >= cnt[p4]) {
    long long t = k / cnt[p4];
    if (t >= p4 - p3) {
      res = p3 - p1;
      r--;
      cnt[p3] += cnt[p4];
      k -= cnt[p4] * (p4 - p3);
      cnt[p4] = 0;
    } else {
      res -= t;
      cout << res << endl;
      return 0;
    }
  } else {
    cout << res << endl;
    return 0;
  }
  return 1;
}
int main() {
  tIn = clock();
  cin >> n >> k;
  set<long long> aux;
  for (int i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    cnt[x]++;
    aux.insert(x);
  }
  if (cnt.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (set<long long>::iterator it = aux.begin(); it != aux.end(); it++)
    pos.push_back(*it);
  l = 0, r = pos.size() - 1;
  res = pos[r] - pos[l];
  while (r - l > 1 && k != 0) {
    p1 = pos[l];
    p2 = pos[l + 1];
    p3 = pos[r - 1];
    p4 = pos[r];
    if (cnt[p1] < cnt[p4]) {
      if (calcL() == 0) return 0;
    } else if (cnt[p1] == cnt[p4]) {
      if (p2 - p1 < p4 - p3) {
        if (calcL() == 0) return 0;
      } else if (calcR() == 0)
        return 0;
    } else {
      if (calcR() == 0) return 0;
    }
  }
  p1 = pos[l];
  p2 = pos[r];
  long long t = min(cnt[p1], cnt[p2]);
  t = k / t;
  if (t >= p2 - p1) {
    cout << 0 << endl;
  } else {
    cout << res - t << endl;
  }
  return 0;
}
