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

int main() {
  int n;
  cin>>n;
  vector<int> h(n+2,0);
  for (size_t i = 1; i <= n; i++) {
    cin>>h[i];
  }
  int sum=0;
  for(size_t i = 0; i <= n; i++){
    sum+=abs(h[i]-h[i+1]);
  }
  cout<<sum/2;
}