#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, a[100003], s, mx = 1, ans;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > mx) mx = a[i];
  }
  s = a[0];
  for (i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) s += abs(a[i] - a[i + 1]);
  }
  ans = min(mx, s);
  cout << ans << endl;
  return 0;
}
