#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 5;
int n;
int a[Maxn], maxn, ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxn = max(a[i], maxn);
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, abs(a[i] - maxn));
  }
  printf("%d", ans);
  return 0;
}
