#include <bits/stdc++.h>
using namespace std;
int N, K;
long long C[500000];
const long long INF = 2e9;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    sum += C[i];
  }
  long long hi = INF, lo = (sum - 1) / N, mid;
  while (hi - lo > 1) {
    mid = (hi + lo) / 2;
    long long move = K;
    for (int i = 0; i < N; i++) {
      move -= max(0LL, C[i] - mid);
    }
    if (move >= 0) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  long long mx = hi;
  hi = sum / N + 1, lo = 0;
  while (hi - lo > 1) {
    mid = (hi + lo) / 2;
    long long move = K;
    for (int i = 0; i < N; i++) {
      move -= max(0LL, mid - C[i]);
    }
    if (move >= 0) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  long long mn = lo;
  cout << mx - mn << endl;
  return 0;
}
