#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const long long INF = 1e9 + 10;
const long long MN = 5e5 + 10;
long long n, k;
long long arr[MN];
void input() {
  cin >> n >> k;
  for (long long i = 0; i < n; ++i) cin >> arr[i];
}
long long bs1(long long l, long long r) {
  if (l == r) return l;
  long long mid = (l + r) / 2;
  long long p = 0;
  for (long long i = 0; i < n; ++i)
    if (arr[i] > mid) p += arr[i] - mid;
  if (p <= k)
    return bs1(l, mid);
  else
    return bs1(mid + 1, r);
}
long long bs2(long long l, long long r) {
  if (l == r) return l;
  long long mid = (l + r + 1) / 2;
  long long p = 0;
  for (long long i = 0; i < n; ++i)
    if (arr[i] < mid) p += mid - arr[i];
  if (p <= k)
    return bs2(mid, r);
  else
    return bs2(l, mid - 1);
}
void solve() {
  long long sum = 0;
  for (long long i = 0; i < n; ++i) sum += arr[i];
  if (sum <= k) {
    if (sum % n == 0)
      cout << 0 << '\n';
    else
      cout << 1 << '\n';
    exit(0);
  }
  sort(arr, arr + n);
  long long t = bs1(0, INF);
  long long p = k;
  for (long long i = 0; i < n; ++i)
    if (arr[i] > t) p -= arr[i] - t, arr[i] = t;
  for (long long i = n - 1; i >= n - p; --i) arr[i]--;
  sort(arr, arr + n);
  t = bs2(0, INF);
  p = k;
  for (long long i = 0; i < n; ++i)
    if (arr[i] < t) p -= t - arr[i], arr[i] = t;
  for (long long i = 0; i < p; ++i) arr[i]++;
  sort(arr, arr + n);
  cout << arr[n - 1] - arr[0] << '\n';
}
int32_t main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  input();
  solve();
  return 0;
}
