#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 5;
const int MAXN = 5e5 + 5;
const long long MOD = 1e9 + 7;
int v[MAXN];
void read_point(complex<double> &a) {
  double x, y;
  scanf("%lf%lf", &x, &y);
  a = complex<double>(x, y);
}
void solve() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = (0); i < (int)(n); i++) {
    scanf("%d", &v[i]);
  }
  int l = 0, r = INF;
  for (; l + 1 < r;) {
    int mid = (l + r) >> 1;
    int sum = k;
    for (int i = (0); i < (int)(n); i++) {
      sum -= max(0, mid - v[i]);
      if (sum < 0) {
        break;
      }
    }
    if (sum >= 0) {
      l = mid;
    } else {
      r = mid;
    }
  }
  int dd = l;
  l = 0, r = INF;
  for (; l + 1 < r;) {
    int mid = (l + r) >> 1;
    int sum = k;
    for (int i = (0); i < (int)(n); i++) {
      sum -= max(0, v[i] - mid);
      if (sum < 0) {
        break;
      }
    }
    if (sum >= 0) {
      r = mid;
    } else {
      l = mid;
    }
  }
  int uu = r;
  int ans = max(0, uu - dd);
  int sum = 0;
  for (int i = (0); i < (int)(n); i++) {
    sum = (sum + v[i]) % n;
  }
  if (sum) {
    ans = max(ans, 1);
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
