#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int inf = 1e9 + 100;
const int N = 1e6 + 5;
long long fpow(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power % 2 == 1) {
      result = (result * base);
    }
    base = (base * base);
    power /= 2;
  }
  return result;
}
vector<int> c;
int main() {
  ios::sync_with_stdio(false);
  int n, k, i;
  long long sum = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    int here;
    cin >> here;
    c.push_back(here);
    sum += here;
  }
  sort(c.begin(), c.end());
  if (sum % n == 0) {
    long long avg = sum / n;
    long long p = 0;
    for (i = 0; i < n; i++) {
      if (c[i] > avg) {
        p += c[i] - avg;
      }
    }
    if (p <= k) {
      cout << "0\n";
      return 0;
    }
  }
  int l = 0, r = inf;
  while (l < r) {
    int mid = (l + r) / 2;
    long long p = 0;
    for (i = 0; i < n; i++) {
      if (c[i] > mid) {
        p += c[i] - mid;
      }
    }
    if (p <= k) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  int ans1 = r;
  l = 0;
  r = inf;
  while (l < r) {
    int mid = (l + r) / 2 + 1;
    long long p = 0;
    for (i = 0; i < n; i++) {
      if (c[i] < mid) {
        p += mid - c[i];
      }
    }
    if (p <= k) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  int ans2 = r;
  cout << max(1, ans1 - ans2) << endl;
  return 0;
}
