#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5e5;
long long c[MaxN + 5];
int main() {
  bool flag;
  int n, z;
  long long k, M, w, res, ans, pos, v;
  scanf("%d %I64d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%I64d", &c[i]);
  sort(c + 1, c + 1 + n);
  M = 0LL;
  ans = 0LL;
  z = n;
  flag = false;
  for (int i = n; i >= 2; i--) {
    res = (c[i] - c[i - 1]) * (long long)(n - i + 1);
    if (k >= res)
      M += res, k -= res, c[i] = c[i - 1], z = i;
    else {
      v = k / (long long)(n - i + 1);
      c[i] -= v;
      M += v * (long long)(n - i + 1);
      for (int j = i + 1; j <= n; j++) c[j] = c[i];
      v = k % (long long)(n - i + 1);
      M += v;
      for (int j = n; j > n - v; j--) c[j]--;
      flag = true;
      break;
    }
  }
  if (!flag)
    for (int i = n; i >= z; i--) c[i] = c[z];
  sort(c + 1, c + 1 + n);
  z = 1;
  flag = false;
  for (int i = 1; i < n; i++) {
    res = (c[i + 1] - c[i]) * (long long)i;
    if (M >= res)
      M -= res, c[i] = c[i + 1], z = i;
    else {
      v = M / (long long)i;
      c[i] += v;
      for (int j = 1; j < i; j++) c[j] = c[i];
      v = M % (long long)i;
      for (int j = 1; j <= (int)v; j++) c[j]++;
      M = 0LL;
      break;
    }
  }
  if (!flag)
    for (int i = 1; i <= z; i++) c[i] = c[z];
  M %= (long long)n;
  for (int i = 1; i <= (int)M; i++) c[i]++;
  sort(c + 1, c + 1 + n);
  pos = c[1];
  for (int j = 2; j <= n; j++) pos = max(pos, c[j]);
  for (int j = 1; j <= n; j++) ans = max(ans, pos - c[j]);
  printf("%I64d\n", ans);
  return 0;
}
