#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  long long m_n = LONG_MAX;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m_n = min(m_n, a[i]);
  }
  m_n += n - 1;
  long long ans1 = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] > m_n) {
      ans1 = max(ans1, abs(a[i] - m_n));
    }
  }
  cout << ans1;
}
