#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, m, x, k, sum1 = 0, sum2 = 0;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long sum = a[0];
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1])
      sum += a[i + 1] - a[i];
    else {
      a[i + 1] += a[i] - a[i + 1];
    }
  }
  cout << sum;
}
