#include <bits/stdc++.h>
using namespace std;
int n;
long long int K, A[510000];
int main() {
  long long int sum = 0;
  scanf("%d%I64d", &n, &K);
  for (int i = 1; i <= n; i++) scanf("%I64d", &A[i]), sum += A[i];
  sort(A + 1, A + n + 1);
  if (A[1] == A[n]) {
    printf("0\n");
    return 0;
  }
  long long int maxv = A[n], rest = K;
  for (int i = n; i >= 1; i--) {
    if (maxv > A[i]) {
      long long int tmp = min(maxv - A[i], rest / (n - i));
      rest -= (n - i) * tmp;
      maxv -= tmp;
    }
  }
  long long int minv = A[1];
  rest = K;
  for (int i = 1; i <= n; i++) {
    if (minv < A[i]) {
      long long int tmp = min(A[i] - minv, rest / (i - 1));
      rest -= (i - 1) * tmp;
      minv += tmp;
    }
  }
  long long int dd;
  if (sum % (long long int)n == 0)
    dd = 0;
  else
    dd = 1;
  printf("%I64d\n", max(dd, maxv - minv));
  return 0;
}
