#include <bits/stdc++.h>
using namespace std;
long long a[500004], n, k, l, r, ansl, ansr, al, ar;
int checkmi(int x) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > x) break;
    sum += x - a[i];
  }
  if (sum <= k)
    return 1;
  else
    return 0;
}
bool checkma(int x) {
  long long sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] < x) break;
    sum += a[i] - x;
  }
  if (sum <= k)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%d%d", &n, &k);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  sort(a, a + n);
  if (sum % n == 0) {
    al = sum / n;
    ar = sum / n;
  } else {
    al = sum / n;
    ar = sum / n + 1;
  }
  l = a[0];
  r = al;
  ansl = a[0];
  ansr = a[0];
  while (l <= r) {
    int mid = (l + r) / 2;
    if (checkmi(mid)) {
      ansl = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = ar;
  r = a[n - 1];
  while (l <= r) {
    int mid = (l + r) / 2;
    if (checkma(mid)) {
      ansr = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ansr - ansl);
  return 0;
}
