#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, d;
  cin >> N;
  vector<int> A(N);
  d = 0;
  for (auto &i : A) {
    int j;
    cin >> j;
    if (d <= j) {
      i = 0;
      d = j;
    } else {
      i = d - j;
    }
  }
  d = 0;
  for (auto i : A) d += i;
  cout << d;
}
