#include <bits/stdc++.h>
using namespace std;
int chh;
const int N = 500005;
int n, m;
int a[N], c[N];
long long b[N];
int main() {
  int l, r, mid, id, x, y, z, maxi, mini;
  long long tmp, tol, cnt;
  while (~scanf("%d %d", &n, &m)) {
    tmp = 0;
    for (int i = (1); i <= (n); i++) {
      scanf("%d", &a[i]);
      tmp += a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = (1); i <= (n); i++) {
      c[i] = tmp / (n - i + 1);
      tmp -= c[i];
    }
    cnt = 0;
    for (int i = (1); i <= (n); i++) {
      if (a[i] < c[i]) cnt += c[i] - a[i];
    }
    if (m >= cnt) {
      printf("%d\n", c[n] - c[1]);
      continue;
    }
    b[0] = 0;
    for (int i = (1); i <= (n); i++) b[i] = b[i - 1] + a[i];
    l = a[1], r = a[n];
    while (l != r) {
      mid = (l + r) >> 1, mid++;
      id = upper_bound(a + 1, a + n + 1, mid) - a;
      tmp = b[n] - b[id - 1] - (long long)(n - id + 1) * mid;
      if (tmp >= m)
        l = mid;
      else
        r = mid - 1;
    }
    id = upper_bound(a + 1, a + n + 1, l) - a;
    tmp = b[n] - b[id - 1] - (long long)(n - id + 1) * l;
    if (tmp == m)
      maxi = l;
    else
      maxi = l + 1;
    l = a[1], r = a[n];
    while (l != r) {
      mid = (l + r) >> 1;
      id = lower_bound(a + 1, a + n + 1, mid) - a;
      id--;
      tmp = (long long)id * mid - b[id];
      if (tmp >= m)
        r = mid;
      else
        l = mid + 1;
    }
    id = lower_bound(a + 1, a + n + 1, l) - a;
    id--;
    tmp = (long long)id * l - b[id];
    if (tmp == m)
      mini = l;
    else
      mini = l - 1;
    printf("%d\n", maxi - mini);
  }
  return 0;
}
