#include <bits/stdc++.h>
struct Input {
  std::vector<int> array;
  long long numOperations;
};
void runTest();
Input parseInput();
long long computeResult(Input& in);
void getUniqueCounts(Input& in, std::vector<int>& array,
                     std::vector<int>& counts);
void printOutput(long long minDifference);
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  runTest();
  return 0;
}
void runTest() {
  Input in = parseInput();
  long long minDifference = computeResult(in);
  printOutput(minDifference);
}
Input parseInput() {
  Input in;
  int numElements;
  std::cin >> numElements >> in.numOperations;
  for (int i = 0; i < numElements; i++) {
    int element;
    std::cin >> element;
    in.array.push_back(element);
  }
  return in;
}
long long computeResult(Input& in) {
  std::vector<int> array;
  std::vector<int> counts;
  getUniqueCounts(in, array, counts);
  int loIndex = 0;
  int loCount = counts[loIndex];
  int hiIndex = array.size() - 1;
  int hiCount = counts[hiIndex];
  while (loIndex < hiIndex) {
    if (loCount <= hiCount) {
      long long adjacentDifference = array[loIndex + 1] - array[loIndex];
      if (in.numOperations / loCount <= adjacentDifference) {
        return array[hiIndex] - array[loIndex] - in.numOperations / loCount;
      }
      in.numOperations -= loCount * adjacentDifference;
      loIndex++;
      loCount += counts[loIndex];
    } else {
      long long adjacentDifference = array[hiIndex] - array[hiIndex - 1];
      if (in.numOperations / hiCount <= adjacentDifference) {
        return array[hiIndex] - array[loIndex] - in.numOperations / hiCount;
      }
      in.numOperations -= hiCount * adjacentDifference;
      hiIndex--;
      hiCount += counts[hiIndex];
    }
  }
  return 0;
}
void getUniqueCounts(Input& in, std::vector<int>& array,
                     std::vector<int>& counts) {
  std::sort(in.array.begin(), in.array.end());
  int currElement = in.array[0];
  int currCount = 1;
  for (int index = 1; index < in.array.size(); index++) {
    if (in.array[index - 1] != in.array[index]) {
      array.push_back(currElement);
      counts.push_back(currCount);
      currElement = in.array[index];
      currCount = 1;
    } else {
      currCount++;
    }
  }
  array.push_back(currElement);
  counts.push_back(currCount);
}
void printOutput(long long minDifference) {
  std::cout << minDifference << std::endl;
}
