#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long n, k, arr[MAXN], ans = 0, a;
vector<long long> vec;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    vec.push_back(a);
  }
  sort(vec.begin(), vec.end());
  long long mn, mx, num1, num2, a1, a2;
  mn = vec[0];
  mx = vec[n - 1];
  num2 = n - (upper_bound(vec.begin(), vec.end(), mx - 1) - vec.begin());
  num1 = upper_bound(vec.begin(), vec.end(), mn) - vec.begin();
  a1 = num1 - 1;
  a2 = n - num2;
  bool bl = 1;
  while (k and bl) {
    if (mn == mx) {
      break;
    }
    if (num2 > num1) {
      if (num1 > k) {
        break;
      }
      long long x = vec[a1 + 1] - vec[a1];
      k = k - (x * num1);
      mn = vec[a1 + 1];
      while (k < 0) {
        mn--;
        k += num1;
        bl = 0;
      }
      num1 = upper_bound(vec.begin(), vec.end(), mn) - vec.begin();
      a1 = num1 - 1;
    } else {
      if (num2 > k) {
        break;
      }
      long long x = vec[a2] - vec[a2 - 1];
      k = k - (x * num2);
      mx = vec[a2 - 1];
      while (k < 0) {
        mx++;
        k += num2;
        bl = 0;
      }
      num2 = n - (upper_bound(vec.begin(), vec.end(), mx - 1) - vec.begin());
      a2 = n - num2;
    }
  }
  cout << mx - mn;
  return 0;
}
