#include <bits/stdc++.h>
using namespace std;
int N;
int K;
int a[1 << 19];
bool canlo(int);
bool canhi(int);
long long s = 0;
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  sort(a, a + N);
  int minelement = 0;
  int lo = a[0];
  int hi = a[N - 1] + 1;
  while (lo < hi) {
    int m = (lo + hi) >> 1;
    if (canlo(m)) {
      lo = m + 1;
    } else {
      hi = m;
    }
  }
  minelement = lo - 1;
  lo = a[0];
  hi = a[N - 1] + 1;
  while (lo < hi) {
    int m = (lo + hi) >> 1;
    if (canhi(m)) {
      hi = m;
    } else {
      lo = m + 1;
    }
  }
  int maxelement = lo;
  if (maxelement <= minelement) {
    if (s % N == 0) {
      printf("0\n");
    } else {
      printf("1\n");
    }
  } else {
    printf("%d", maxelement - minelement);
  }
}
bool canlo(int m) {
  long long cnt = 0;
  for (int i = 0; i < N && cnt <= K; i++) {
    cnt += max(0, m - a[i]);
  }
  return cnt <= K;
}
bool canhi(int m) {
  long long cnt = 0;
  for (int i = 0; i < N && cnt <= K; i++) {
    cnt += max(0, a[i] - m);
  }
  return cnt <= K;
}
