#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, i, Re, total = 0, maxS = 0, minN = 0;
  cin >> N;
  int a[N];
  for (i = 0; i < N; ++i) {
    cin >> a[i];
  };
  maxS = a[0];
  minN = a[1];
  for (i = 0; i <= N; ++i) {
    if (a[i] > a[i + 1]) {
      if (maxS >= a[i]) {
        maxS = maxS;
      } else {
        maxS = a[i];
      };
      if (minN <= a[i + 1]) {
        minN = minN;
      } else {
        minN = a[i + 1];
      }
      a[i] = a[i + 1];
    }
  }
  Re = maxS - minN;
  cout << Re << endl;
  return 0;
}
