#include <bits/stdc++.h>
const int oo = 2139063143;
const int N = 1010000;
const int P = 1000000007;
using namespace std;
template <typename T>
inline void sc(T &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
template <typename T>
inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void pr(T x) {
  print(x), putchar('\n');
}
pair<long long, long long> b[N];
long long a[N];
int main() {
  long long n;
  sc(n);
  long long m;
  sc(m);
  for (int i = 1; i <= n; i++) sc(a[i]);
  sort(a + 1, a + n + 1);
  long long cur = 0, tot = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (a[i - 1] && a[i] != a[i - 1])
      b[++tot] = make_pair(a[i - 1], cur), cur = 0;
    ++cur;
  }
  n = tot;
  long long l = 1, r = n;
  while (m && l != r) {
    long long g1 = b[l].second;
    long long g2 = b[r].second;
    if (g1 <= g2) {
      long long d = min(b[l + 1].first - b[l].first, m / b[l].second);
      if (!d) break;
      b[l].first += d;
      m -= d * b[l].second;
      if (b[l].first == b[l + 1].first) b[l + 1].second += b[l].second, ++l;
    } else {
      long long d = min(b[r].first - b[r - 1].first, m / b[r].second);
      if (!d) break;
      b[r].first -= d;
      m -= d * b[r].second;
      if (b[r].first == b[r - 1].first) b[r - 1].second += b[r].second, --r;
    }
  }
  pr(b[r].first - b[l].first);
  return 0;
}
