#include <bits/stdc++.h>
using namespace std;
int coin[500010];
int check1(int num, int n, int k) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (coin[i] < num) {
      sum += num - coin[i];
    }
  }
  return sum <= k;
}
int check2(int num, int n, int k) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (coin[i] > num) {
      sum += coin[i] - num;
    }
  }
  return sum <= k;
}
int main() {
  int n, k;
  int minUp, maxDown;
  int le, rig, re1, re2;
  long long sum;
  while (scanf("%d%d", &n, &k) != EOF) {
    sum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &coin[i]);
      sum += coin[i];
    }
    sort(coin, coin + n);
    sum % n == 0 ? (minUp = maxDown = sum / n)
                 : (minUp = sum / n, maxDown = sum / n + 1);
    le = 1, rig = minUp;
    while (le <= rig) {
      int mid = (le + rig) >> 1;
      if (check1(mid, n, k)) {
        le = mid + 1;
      } else {
        rig = mid - 1;
      }
    }
    re1 = rig;
    le = maxDown, rig = 1e9;
    while (le <= rig) {
      int mid = (le + rig) >> 1;
      if (check2(mid, n, k)) {
        rig = mid - 1;
      } else {
        le = mid + 1;
      }
    }
    re2 = le;
    printf("%d\n", re2 - re1);
  }
  return 0;
}
