#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int &e : h) cin >> e;
  
  int tesu = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0) tesu += h[0];
    else if (h[i-1] < h[i]) tesu += h[i]-h[i-1];
  }
  cout << tesu << endl;
}