#include <bits/stdc++.h>
using namespace std;
static struct IO {
  char tmp[1 << 10];
  char cur;
  inline char nextChar() { return cur = getc(stdin); }
  inline char peekChar() { return cur; }
  inline operator bool() { return peekChar(); }
  inline static bool isBlank(char c) { return (c < '-' && c); }
  inline bool skipBlanks() {
    while (isBlank(nextChar()))
      ;
    return peekChar() != 0;
  }
  inline IO& operator>>(char& c) {
    c = nextChar();
    return *this;
  }
  inline IO& operator>>(char* buf) {
    if (skipBlanks()) {
      if (peekChar()) {
        *(buf++) = peekChar();
        while (!isBlank(nextChar())) *(buf++) = peekChar();
      }
      *(buf++) = 0;
    }
    return *this;
  }
  inline IO& operator>>(string& s) {
    if (skipBlanks()) {
      s.clear();
      s += peekChar();
      while (!isBlank(nextChar())) s += peekChar();
    }
    return *this;
  }
  inline IO& operator>>(double& d) {
    if ((*this) >> tmp) sscanf(tmp, "%lf", &d);
    return *this;
  }
  inline IO& operator>>(int& n) {
    if (skipBlanks()) {
      int sign = +1;
      if (peekChar() == '-') {
        sign = -1;
        n = nextChar() - '0';
      } else
        n = peekChar() - '0';
      while (!isBlank(nextChar())) {
        n += n + (n << 3) + peekChar() - 48;
      }
      n *= sign;
    }
    return *this;
  }
  inline IO& operator>>(unsigned int& n) {
    if (skipBlanks()) {
      int sign = +1;
      if (peekChar() == '-') {
        sign = -1;
        n = nextChar() - '0';
      } else
        n = peekChar() - '0';
      while (!isBlank(nextChar())) {
        n += n + (n << 3) + peekChar() - 48;
      }
      n *= sign;
    }
    return *this;
  }
  inline IO& operator>>(long long& n) {
    if (skipBlanks()) {
      int sign = +1;
      if (peekChar() == '-') {
        sign = -1;
        n = nextChar() - '0';
      } else
        n = peekChar() - '0';
      while (!isBlank(nextChar())) {
        n += n + (n << 3) + peekChar() - 48;
      }
      n *= sign;
    }
    return *this;
  }
  inline void putChar(char c) { putc(c, stdout); }
  inline IO& operator<<(char c) {
    putChar(c);
    return *this;
  }
  inline IO& operator<<(const char* s) {
    while (*s) putChar(*s++);
    return *this;
  }
  inline IO& operator<<(const string& s) {
    for (int i = 0; i < (int)s.size(); ++i) putChar(s[i]);
    return *this;
  }
  char* toString(double d) {
    sprintf(tmp, "%lf%c", d, '\0');
    return tmp;
  }
  inline IO& operator<<(double d) { return (*this) << toString(d); }
  inline char* toString(int n) {
    char* p = (tmp + 30);
    if (n) {
      bool isNeg = 0;
      if (n < 0) isNeg = 1, n = -n;
      while (n) *--p = (n % 10) + '0', n /= 10;
      if (isNeg) *--p = '-';
    } else
      *--p = '0';
    return p;
  }
  inline IO& operator<<(int n) { return (*this) << toString(n); }
  inline char* toString(long long n) {
    char* p = (tmp + 30);
    if (n) {
      bool isNeg = 0;
      if (n < 0) isNeg = 1, n = -n;
      while (n) *--p = (n % 10) + '0', n /= 10;
      if (isNeg) *--p = '-';
    } else
      *--p = '0';
    return p;
  }
  inline IO& operator<<(long long n) { return (*this) << toString(n); }
} __io__;
long long n, k, l, r, m, res_min, res_max, sum_c;
int t[500007];
bool Min(int a) {
  long long sum = 0;
  for (int i = 0; i < (n); ++i) {
    sum += max(0, a - t[i]);
  }
  return sum <= k;
}
bool Max(int a) {
  long long sum = 0;
  for (int i = 0; i < (n); ++i) {
    sum += max(0, t[i] - a);
  }
  return sum <= k;
}
int main() {
  __io__ >> n >> k;
  for (int i = 0; i < (n); ++i) {
    __io__ >> t[i];
    sum_c += t[i];
  }
  l = 0, r = 1e9;
  while (l < r) {
    m = (l + r) / 2;
    if (l == m) ++m;
    if (Min(m))
      l = m;
    else
      r = m - 1;
  }
  res_min = l;
  l = 0, r = 1e9;
  while (l < r) {
    m = (l + r) / 2;
    if (m == r) --m;
    if (Max(m))
      r = m;
    else
      l = m + 1;
  }
  res_max = l;
  if (res_max <= res_min) {
    if (sum_c == ((sum_c / n) * n)) {
      __io__ << 0;
      return 0;
    } else {
      __io__ << 1;
      return 0;
    }
  }
  __io__ << res_max - res_min;
}
