#include <bits/stdc++.h>
using namespace std;
int a[500010], n, k;
bool c1(int mid) {
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= mid) break;
    sum += mid - a[i];
  }
  return sum <= k;
}
bool c2(int mid) {
  long long sum = 0;
  for (int i = n; i >= 1; --i) {
    if (a[i] <= mid) break;
    sum += a[i] - mid;
  }
  return sum <= k;
}
int main() {
  scanf("%d%d", &n, &k);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  sort(a + 1, a + n + 1);
  long long mod = sum % n;
  int l = 1, r = sum / n, ans;
  while (l <= r) {
    int mid = l + ((r - l) >> 1);
    if (c1(mid)) {
      l = mid + 1;
      ans = mid;
    } else
      r = mid - 1;
  }
  l = ans + !(mod == 0);
  r = a[n];
  int ans2;
  while (l <= r) {
    int mid = l + ((r - l) >> 1);
    if (c2(mid)) {
      r = mid - 1;
      ans2 = mid;
    } else
      l = mid + 1;
  }
  ans = ans2 - ans;
  printf("%d\n", ans);
  return 0;
}
