#include <iostream>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
ll v[N];
int main(){
int n; cin >> n;
ll minv = 1e9 + 10;
ll res = 0;
for(int i = 0; i < n; i ++ ){
cin >> v[i];
minv = min(minv, v[i]);
res = max(v[i] - minv, res);
}
cout << res << endl;
return 0;
}