#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int n, k, a[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  long long l = 1, r = 2e9;
  int mn, mx, K = k;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long need = 0;
    for (int i = 0; i < n; ++i) need += max(0LL, mid - a[i]);
    if (need <= k) {
      mn = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  for (int i = 0; i < n; ++i) {
    K -= max(0, mn - a[i]);
    a[i] = max(mn, a[i]);
  }
  for (int i = 0; i < n && K > 0; ++i)
    if (a[i] == mn) ++a[i], --K;
  l = 1, r = 2e9;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long need = 0;
    for (int i = 0; i < n; ++i) need += max(0LL, a[i] - mid);
    if (need <= k) {
      mx = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  K = k;
  for (int i = 0; i < n; ++i) {
    K -= max(0, a[i] - mx);
    a[i] = min(mx, a[i]);
  }
  for (int i = 0; i < n && K > 0; ++i)
    if (a[i] == mx) --a[i], --K;
  mx = mn = a[0];
  for (int i = 1; i < n; ++i) {
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }
  printf("%d\n", mx - mn);
  return 0;
}
