#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
long long int arr[maxn], pre[maxn], suf[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k, i;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> arr[i];
  sort(arr + 1, arr + n + 1);
  for (i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + arr[i];
  }
  long long int poor = arr[1], rich = arr[n];
  for (i = 1; i <= n; i++) {
    if (i * arr[i] - pre[i] >= k) break;
    poor = arr[i] + (k - i * arr[i] + pre[i]) / i;
  }
  for (i = n; i > 0; i--) {
    suf[i] = suf[i + 1] + arr[i];
    if (suf[i] - (n - i + 1) * arr[i] >= k) break;
    rich = arr[i] - (k - suf[i] + (n - i + 1) * arr[i]) / (n - i + 1);
  }
  if (rich < poor) rich = poor;
  if (pre[n] % n && rich == poor) rich++;
  cout << rich - poor;
  return 0;
}
