#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main ()
{
//'freopen("in.txt","r",stdin);
int n=0;
int day=0;
cin>>n;
int d[100000];
for(int i=1;i<=n;i++)//the road
{
cin>>d[i];
//cout<<d[i];
}
for(int i=1;i<=n;i++)// turn them to zero one by one
{
while(d[i]!=0)//if the current part isn't zero,make it zero
{
int b=i;//end
for (int a=i;a<=n;a++)//find the end of the part to build
{ if (d[a]==0)
{ b=a-1;
break;
}
b=a;
}
for (int c=i;c<=b;c++)//build
{
d[c]=d[c]-1;
}
day++;
}
}
cout<<day;
return 0;
}