#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500500;
int a[MAXN];
int n, k, low, high;
bool check1(int md) {
  long long balance = 0;
  for (int i = 1; i <= n; i++) {
    balance += (a[i] - md);
  }
  if (balance < 0) return false;
  long long t = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < md) {
      t += (md - a[i]);
    }
  }
  return t <= k;
}
bool check2(int x) {
  long long balance = 0;
  for (int i = 1; i <= n; i++) balance -= (a[i] - x);
  if (balance < 0) return false;
  long long t = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] > x) t += (a[i] - x);
  return t <= k;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  low = 0;
  high = 1e9;
  int g = 0;
  for (int iter = 0; iter < 40; iter++) {
    int md = (low + high) / 2;
    if (check1(md)) {
      g = max(g, md);
      low = md + 1;
    } else {
      high = md;
    }
  }
  low = 0;
  high = 1e9;
  int f = 1e9;
  for (int iter = 0; iter < 40; iter++) {
    int md = (low + high) / 2;
    if (check2(md)) {
      f = min(f, md);
      high = md;
    } else
      low = md;
  }
  cout << f - g;
  int end;
  cin >> end;
  return 0;
}
