#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e6 + 10;
long long int money[maxx];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<long long int> a(n + 1);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  long long int low = 1, high = 1e12;
  long long int t = 0;
  while (low < high) {
    long long int mid = ((low + high) >> 1) + 1;
    t = 0;
    for (int i = 1; i <= n; i++) {
      if (mid - a[i] > 0) t += mid - a[i];
    }
    if (t <= k) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  t = k;
  for (int i = 1; i <= n; i++) {
    t -= max(0LL, low - a[i]);
    a[i] = max(a[i], low);
  }
  for (int i = 1; i <= n; i++) {
    if (t and a[i] == low) {
      t--;
      a[i]++;
    }
  }
  low = 1, high = 1e12;
  while (low < high) {
    long long int mid = ((low + high) >> 1);
    t = 0;
    for (int i = 1; i <= n; i++) {
      t += max(0LL, a[i] - mid);
    }
    if (t <= k) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  t = k;
  for (int i = 1; i <= n; i++) {
    t -= max(0LL, a[i] - low);
    a[i] = min(a[i], low);
  }
  for (int i = 1; i <= n; i++) {
    if (t and a[i] == low) {
      t--;
      a[i]--;
    }
  }
  cout << *max_element(a.begin() + 1, a.end()) -
              *min_element(a.begin() + 1, a.end())
       << '\n';
  return 0;
}
