#include <bits/stdc++.h>
using namespace std;
const int maxn = 500500;
int n, k;
int w[maxn];
long long ps[maxn];
long long sum;
int ave;
bool checkp(int v) {
  int p = lower_bound(w, w + n, v) - w - 1;
  if ((long long)v * (p + 1) - ps[p] > k)
    return false;
  else
    return true;
}
bool checkr(int v) {
  int p = upper_bound(w, w + n, v) - w;
  if (ps[n - 1] - ps[p - 1] - (long long)(n - p) * v > k)
    return false;
  else
    return true;
}
void ir() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &w[i]);
  sort(w, w + n);
  sum = 0;
  for (int i = 0; i < n; ++i) {
    ps[i] = (sum += w[i]);
  }
  ave = sum / n;
}
int main() {
  ir();
  int l, r;
  int mini, maxi;
  l = w[0];
  r = ave + 1;
  while ((l + 1) < r) {
    int mid = (l + r) >> 1;
    if (checkp(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  mini = l;
  l = ave;
  if (sum % n) ++l;
  r = w[n - 1];
  while (l < r) {
    int mid = (l + r) >> 1;
    if (checkr(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  maxi = r;
  printf("%d\n", maxi - mini);
  return 0;
}
