#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long arr[100005];
long long pref[100005];
long long calc(long long mid, long long x) {
  long long sum = 0;
  for (int i = 1; i < n + 1; i++) {
    if (arr[i] < mid) {
      sum += mid - arr[i];
    }
    if (arr[i] > mid + x) {
      sum += arr[i] - mid - x;
    }
  }
  return sum;
}
bool f(long long xr) {
  int low = 0, high = 1e9;
  while (low < high) {
    int mid = (low + high) / 2;
    int mid1 = mid + 1;
    int mid2 = mid - 1;
    long long x = calc(mid1, xr);
    long long y = calc(mid2, xr);
    long long z = calc(mid, xr);
    if (x >= z && z >= y) {
      high = mid;
    } else if (z <= y && z <= x) {
      low = mid;
      break;
    } else {
      low = mid + 1;
    }
  }
  if (calc(low, xr) <= k) {
    return 1;
  } else
    return 0;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < n + 1; i++) {
    cin >> arr[i];
  }
  sort(arr + 1, arr + n + 1);
  int low = 0, high = 1e9;
  while (low < high) {
    int mid = (low + high) / 2;
    if (f(mid)) {
      high = mid;
    } else
      low = mid + 1;
  }
  cout << low;
}
