#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <typename T>
ostream& operator<<(ostream& out, vector<T>& p) {
  for (auto& el : p) out << el << ' ';
  return out;
}
template <typename T>
istream& operator>>(istream& inp, vector<T>& p) {
  for (auto& el : p) inp >> el;
  return inp;
}
template <typename T>
ostream& operator<<(ostream& out, deque<T>& p) {
  for (auto& el : p) out << el << ' ';
  return out;
}
template <typename T>
istream& operator>>(istream& inp, deque<T>& p) {
  for (auto& el : p) inp >> el;
  return inp;
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
  out << p.first << ' ' << p.second << endl;
  return out;
}
template <class T1, class T2>
istream& operator>>(istream& inp, pair<T1, T2>& p) {
  inp >> p.first >> p.second;
  return inp;
}
}  // namespace IO
using namespace IO;
const long long M1 = 1e9 + 7;
const long long M2 = 1e9 - 7;
const long long B1 = 29;
const long long B2 = 73;
const long long INF = 4e18;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long n, k;
vector<long long> a;
long long c1(long long p, long long m) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= p && a[i] <= p + m) continue;
    if (a[i] < p) sum += abs(a[i] - p);
    if (a[i] > p + m) sum += abs(p + m - a[i]);
  }
  return k - sum;
}
bool check(long long m) {
  long long l = a.back();
  long long r = a[0];
  while (r - l > 2) {
    long long m1 = (l * 2 + r) / 3;
    long long m2 = (r * 2 + l) / 3;
    if (c1(m1, m) < c1(m2, m))
      l = m1;
    else
      r = m2;
  }
  for (long long i = l; i <= r; i++)
    if (c1(i, m) >= 0) return true;
  return false;
}
signed main() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  a.resize(n);
  cin >> a;
  sort(a.rbegin(), a.rend());
  long long l = -1;
  long long r = abs(a[0] - a.back());
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m;
  }
  cout << r;
  return 0;
}
