#include <bits/stdc++.h>
using namespace std;
long long MAX = 1000000007;
int Array[500005];
long long PS[500005];
int N, k;
int FindIndex(int low, int high, int key) {
  if (low >= high)
    return low;
  else {
    int middle = (low + high) >> 1;
    if (Array[middle] <= key)
      return FindIndex(middle + 1, high, key);
    else
      return FindIndex(low, middle - 1, key);
  }
}
int BinarySearchTop(int low, int high) {
  if (low >= high)
    return low;
  else {
    int middle = (low + high) >> 1;
    int index = FindIndex(1, N, middle);
    if (Array[index] > middle) --index;
    long long Temp = (PS[N] - PS[index]) - (middle * 1LL * (N - index));
    if (Temp == k)
      return middle;
    else if (Temp > k)
      return BinarySearchTop(middle + 1, high);
    else
      return BinarySearchTop(low, middle - 1);
  }
}
int BinarySearchBottom(int low, int high) {
  if (low >= high)
    return low;
  else {
    int middle = (low + high) >> 1;
    int index = FindIndex(1, N, middle);
    if (Array[index] > middle) --index;
    long long Temp = (middle * 1LL * index) - PS[index];
    if (Temp == k)
      return middle;
    else if (Temp > k)
      return BinarySearchBottom(low, middle - 1);
    else
      return BinarySearchBottom(middle + 1, high);
  }
}
int main() {
  scanf("%d%d", &N, &k);
  for (int i = 1; i <= N; ++i) scanf("%d", Array + i);
  sort(Array + 1, Array + N + 1);
  for (int i = 1; i <= N; ++i) PS[i] = PS[i - 1] + Array[i];
  int top = BinarySearchTop(Array[1], Array[N]);
  int index = FindIndex(1, N, top);
  if (Array[index] > top) --index;
  long long Temp = (PS[N] - PS[index]) - (top * 1LL * (N - index));
  if (Temp > k) ++top;
  int bottom = BinarySearchBottom(Array[1], Array[N]);
  index = FindIndex(1, N, bottom);
  if (Array[index] > bottom) --index;
  Temp = (index * 1LL * bottom) - PS[index];
  if (Temp > k) --bottom;
  if (bottom < top)
    printf("%d\n", top - bottom);
  else {
    if (PS[N] % N == 0)
      puts("0");
    else
      puts("1");
  }
  return 0;
}
