#include <bits/stdc++.h>
using namespace std;
int N, K;
long long C[505050];
void pohe() {
  long long sum = 0;
  for (int i = N - 1; i >= 0; --i) {
    sum += C[i];
    long long bk = (i == 0 ? 0 : C[i - 1]) * (N - i);
    if (sum - bk > K) {
      long long rem = sum - bk - K;
      long long rr = rem % (N - i);
      for (int j = i; j < N; ++j) {
        C[j] = C[i - 1] + rem / (N - i) + (N - j - 1 < rr ? 1 : 0);
      }
      break;
    }
  }
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; ++i) {
    int t;
    scanf("%d", &t);
    C[i] = t;
  }
  sort(C, C + N);
  long long tot = 0;
  for (int i = 0; i < N; ++i) tot += C[i];
  if (tot <= K) {
    printf("%d\n", (tot % N == 0) ? 0 : 1);
    return 0;
  }
  pohe();
  for (int i = 0; i < N; ++i) C[i] = 21000000 - C[i];
  reverse(C, C + N);
  pohe();
  for (int i = 0; i < N; ++i) C[i] = 21000000 - C[i];
  reverse(C, C + N);
  printf("%d\n", (int)(C[N - 1] - C[0]));
  return 0;
}
