#include <bits/stdc++.h>
using namespace std;
int n, kk;
int arr[500010];
long long sum, del, aver;
bool bin1(long long x) {
  long long res = 0;
  for (int i = 1; i <= n; ++i)
    if (arr[i] > x) res += arr[i] - x;
  return res <= kk;
}
bool bin2(long long x) {
  long long res = 0;
  for (int i = 1; i <= n; ++i)
    if (arr[i] < x) res += x - arr[i];
  return res <= kk;
}
void init() {
  sum = del = 0;
  cin >> n >> kk;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", arr + i);
    sum += arr[i];
  }
  aver = sum / n;
  if (sum % n) ++del;
  long long ll = aver + del, rr = 1e9;
  long long lans = 1, rans = 1e9;
  while (ll <= rr) {
    long long mid = (ll + rr) >> 1;
    if (bin1(mid)) {
      rans = mid;
      rr = mid - 1;
    } else
      ll = mid + 1;
  }
  ll = 1, rr = aver;
  while (ll <= rr) {
    long long mid = (ll + rr) >> 1;
    if (bin2(mid)) {
      lans = mid;
      ll = mid + 1;
    } else
      rr = mid - 1;
  }
  cout << rans - lans << "\n";
  return;
}
int main() {
  init();
  return 0;
}
