#include <bits/stdc++.h>
using namespace std;
string s;
long long arr[600100];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long long arrSum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    arrSum += arr[i];
  }
  long long highRange = 0;
  int l = 0;
  int r = 1000000000;
  int ans = r;
  int mid = (l + r) / 2;
  while (l <= r) {
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      sum += max(0LL, arr[i] - mid);
    }
    if (sum <= k) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
    mid = (l + r) / 2;
  }
  highRange = ans;
  l = 0;
  r = 1000000000;
  ans = r;
  mid = (l + r) / 2;
  while (l <= r) {
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      sum += max(0LL, mid - arr[i]);
    }
    if (sum <= k) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
    mid = (l + r) / 2;
  }
  long long lowRange = ans;
  if (lowRange < highRange)
    printf("%lld", highRange - lowRange);
  else if (arrSum % n == 0)
    printf("0");
  else
    printf("1");
}
