#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int ar[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> ar[i];
  int l = 1, r = 1e9;
  while (l < r) {
    int m = (l + r + 1) / 2;
    int tmp = k;
    for (int i = 1; i <= n; ++i) {
      if (ar[i] < m) tmp -= (m - ar[i]);
      if (tmp < 0) break;
    }
    if (tmp >= 0) {
      l = m;
    } else {
      r = m - 1;
    }
  }
  int l2 = 1, r2 = 1e9;
  while (l2 < r2) {
    int m = (l2 + r2) / 2;
    int tmp = k;
    for (int i = 1; i <= n; ++i) {
      if (ar[i] > m) tmp -= (ar[i] - m);
      if (tmp < 0) break;
    }
    if (tmp >= 0) {
      r2 = m;
    } else {
      l2 = m + 1;
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += ar[i];
  }
  if (sum % n == 0)
    cout << max(l2 - l, 0) << endl;
  else
    cout << max(l2 - l, 1) << endl;
  return 0;
}
