#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
long long val[N], sum[N];
int n, k;
bool lcal(long long m) {
  int p = lower_bound(val + 1, val + 1 + n, m) - val - 1;
  long long lt = p * m - sum[p], rt = sum[n] - sum[p] - (n - p) * m;
  return lt > k || lt > rt;
}
bool rcal(long long m) {
  int p = upper_bound(val + 1, val + 1 + n, m) - val - 1;
  long long lt = p * m - sum[p], rt = sum[n] - sum[p] - (n - p) * m;
  return rt > k || lt < rt;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%I64d", val + i);
  sort(val + 1, val + 1 + n);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + val[i];
  long long l = val[1], r = val[n] + 1;
  while (r - l > 1) {
    long long m = (r + l) >> 1;
    lcal(m) ? r = m : l = m;
  }
  long long ansl = l;
  l = val[1] - 1, r = val[n];
  while (r - l > 1) {
    long long m = (r + l) >> 1;
    rcal(m) ? l = m : r = m;
  }
  printf("%I64d\n", r - ansl);
  return 0;
}
