#include<iostream>using namespace std;int main(){ int ji=0,n,h[100005]; cin>>n; for(int i=1;i<=n;i++) cin>>h[i]; for(int i=0;i<n;i++) if(h[i]<h[i+1]) ji+=h[i+1]-h[i]; cout<<ji<<endl; return 0;}