#include <bits/stdc++.h>
using namespace std;
const int N = 513245;
int a[N];
int n, k;
int maxx, minn = 1e9;
bool checkmin(int x) {
  int s = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < x) {
      s += x - a[i];
    }
    if (s > k) return 0;
  }
  return 1;
}
bool checkmax(int x) {
  int s = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > x) {
      s += a[i] - x;
    }
    if (s > k) return 0;
  }
  return 1;
}
int findmax() {
  int l = minn - 1, r = maxx;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (checkmax(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  return r;
}
int findmin() {
  int l = minn, r = maxx + 1;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (checkmin(m)) {
      l = m;
    } else {
      r = m;
    }
  }
  return l;
}
int main() {
  int i, j;
  cin >> n >> k;
  long long s = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxx = max(maxx, a[i]);
    minn = min(minn, a[i]);
    s += a[i];
  }
  int t = (s % n != 0);
  int x = findmax();
  int y = findmin();
  cout << max(x - y, t);
  return 0;
}
