#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, k, A[N], L, R, Min, Max;
long long Sum, Ave;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &A[i]), Sum += A[i], Max = max(Max, A[i]);
  Ave = Sum / n;
  L = 1, R = Ave;
  while (L <= R) {
    int mid = (L + R) >> 1;
    long long tmp = 0;
    for (int i = 1; i <= n; i++) tmp += max(0, mid - A[i]);
    if (tmp <= k)
      L = (Min = mid) + 1;
    else
      R = mid - 1;
  }
  if (Ave * n != Sum) Ave++;
  L = Ave, R = Max + 1;
  while (L <= R) {
    int mid = (L + R) >> 1;
    long long tmp = 0;
    for (int i = 1; i <= n; i++) tmp += max(0, A[i] - mid);
    if (tmp <= k)
      R = (Max = mid) - 1;
    else
      L = mid + 1;
  }
  printf("%d\n", Max - Min);
}
