#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  long long mn = sum / n;
  long long mx = mn;
  if (mn * n != sum) mx++;
  long long left = 0, right = mn + 1;
  while (right - left > 1) {
    long long mid = (left + right) >> 1;
    long long rem = k;
    for (int i = 0; i < n; ++i) {
      if (a[i] < mid) rem -= mid - a[i];
      if (rem < 0) break;
    }
    if (rem >= 0)
      left = mid;
    else
      right = mid;
  }
  long long a1 = left;
  left = mx - 1;
  right = (int)2e9;
  while (right - left > 1) {
    long long mid = (left + right) >> 1;
    long long rem = k;
    for (int i = 0; i < n; ++i) {
      if (a[i] > mid) rem -= a[i] - mid;
      if (rem < 0) break;
    }
    if (rem >= 0)
      right = mid;
    else
      left = mid;
  }
  long long a2 = right;
  cout << a2 - a1;
  return 0;
}
