#include <bits/stdc++.h>
using namespace std;
int a[500000 + 10], n, k;
long long sum = 0;
int ans, l, r, maxx, minn;
inline void get_ready() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
}
inline bool pan2(int x) {
  long long cnt = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] > x) {
      cnt += (long long)(a[i] - x);
    } else
      break;
  }
  if (cnt > k) return 0;
  return 1;
}
inline bool pan(int x) {
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < x) {
      cnt += (long long)(x - a[i]);
    } else
      break;
  }
  if (cnt > k) return 0;
  return 1;
}
inline void slove() {
  if (sum % n == 0)
    minn = maxx = sum / n;
  else {
    maxx = sum / n;
    minn = maxx + 1;
  }
  sort(a + 1, a + n + 1);
  r = 1e9 + 1;
  l = minn;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (!pan2(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  ans = l;
  l = 1;
  r = maxx;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (pan(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans - r << endl;
}
int main() {
  get_ready();
  slove();
  return 0;
}
