#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, m = 0, ans = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> x;
    if (x < m) ans += (m - x);
    m = max(m, x);
  }
  cout << m;
  return 0;
}
