#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const unsigned long long mxx = 1333331;
inline void RI(int &x) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0';
}
int a[500010];
int n, k;
int main() {
  int min1 = 0, max1 = 0;
  cin >> n >> k;
  long long xxx = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    xxx += a[i];
  }
  sort(a, a + n);
  long long ll = 0, rr = 1e9;
  while (ll < rr) {
    long long mid = (ll + rr) / 2;
    long long temp = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] < mid) {
        temp += (mid - a[i]);
      } else
        break;
    }
    if (temp <= k) {
      ll = mid;
    } else {
      rr = mid - 1;
    }
    if (rr - ll == 1) {
      break;
    }
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < rr) {
      sum += (rr - a[i]);
    } else {
      break;
    }
  }
  if (sum <= k)
    min1 = rr;
  else
    min1 = ll;
  ll = 0, rr = 1e9;
  while (ll < rr) {
    long long mid = (ll + rr) / 2;
    long long temp = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] > mid) {
        temp += (a[i] - mid);
      } else {
        break;
      }
    }
    if (temp <= k) {
      rr = mid;
    } else {
      ll = mid + 1;
    }
    if (rr - ll == 1) {
      break;
    }
  }
  long long temp = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] > ll) {
      temp += (a[i] - ll);
    } else {
      break;
    }
  }
  if (temp <= k)
    max1 = ll;
  else
    max1 = rr;
  if (min1 < max1) {
    cout << max1 - min1 << endl;
  } else {
    if (xxx % n == 0)
      cout << "0" << endl;
    else
      cout << "1" << endl;
  }
  return 0;
}
