#include <bits/stdc++.h>
const int size = 1e5 + 5;
long long k;
int n;
int a[size];
int min = std::numeric_limits<int>::max();
int max = std::numeric_limits<int>::min();
long long Evaluate(long long l, long long r) {
  long long ret = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] < l) {
      ret += l - a[i];
    }
    if (r < a[i]) {
      ret += a[i] - r;
    }
  }
  return ret;
}
bool Ternary(int diff) {
  int s = min;
  int e = max;
  while (s <= e) {
    int mid1 = s + (e - s) / 3;
    int mid2 = e - (e - s) / 3;
    long long val1 = Evaluate(mid1, std::min(mid1 + diff, max));
    long long val2 = Evaluate(mid2, std::min(mid2 + diff, max));
    if (val1 <= k || val2 <= k) {
      return true;
    }
    if (val1 <= val2) {
      e = mid2 - 1;
    } else {
      s = mid1 + 1;
    }
  }
  return false;
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    min = std::min(min, a[i]);
    max = std::max(max, a[i]);
  }
  int s = 0;
  int e = max - min;
  int ans = 0;
  while (s <= e) {
    int mid = s + (e - s) / 2;
    if (Ternary(mid)) {
      ans = mid;
      e = mid - 1;
    } else {
      s = mid + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
