#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const long long MOD2 = 998244353;
const long long N = 501010;
const long long N2 = 1000 * 1000;
const long double PI = 3.14159265;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  map<long long, long long> m;
  std::vector<long long> v;
  for (long long i = 0; i < n; ++i) {
    long long dum;
    cin >> dum;
    m[dum]++;
  }
  if (m.size() == 1) {
    cout << 0 << "\n";
    exit(0);
  }
  for (auto x : m) {
    v.push_back(x.first);
  }
  long long l = 0, r = v.size() - 1;
  while (k > 0 && l != r) {
    if (m[v[l]] < m[v[r]]) {
      long long req = v[l + 1] - v[l];
      req *= m[v[l]];
      if (k >= req) {
        k -= req;
        m[v[l + 1]] += m[v[l]];
        l++;
      } else {
        k /= m[v[l]];
        long long ans = v[r] - v[l] - k;
        cout << ans << "\n";
        return 0;
      }
    } else {
      long long req = v[r] - v[r - 1];
      req *= m[v[r]];
      if (k >= req) {
        k -= req;
        m[v[r - 1]] += m[v[r]];
        r--;
      } else {
        k /= m[v[r]];
        long long ans = v[r] - v[l] - k;
        cout << ans << "\n";
        return 0;
      }
    }
  }
  cout << v[r] - v[l];
  return 0;
}
