#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  int ar[n + 1];
  for (int i = 1; i <= n; i++) cin >> ar[i];
  long long eng = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (!i) {
      ans += ar[i + 1];
      continue;
    }
    if (ar[i] >= ar[i + 1]) {
      eng += ar[i] - ar[i + 1];
    } else {
      if (eng >= (ar[i + 1] - ar[i]))
        eng -= ar[i + 1] - ar[i];
      else {
        ans += (ar[i + 1] - ar[i]) - eng;
        eng = 0;
      }
    }
  }
  cout << ans;
  return 0;
}
