#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int h[105];
  int count=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  count+=h[0];
  for(int i=1;i<n;i++){
    if(h[i]>h[i-1]){
      count+=h[i]-h[i-1];
    }
  }
  cout<<count<<endl;
  return 0;
}
