import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] h=new int[n+1];
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        }
        h[n]=0;
        long ans=0;
        int sum=1;
        while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        }
        out.println(ans);
    }
} import java.util.*; util.* java import java.awt.*; awt.* java import java.awt.geom.*; geom.* java.awt import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] h=new int[n+1];
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        }
        h[n]=0;
        long ans=0;
        int sum=1;
        while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        }
        out.println(ans);
    }
} Main public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] h=new int[n+1];
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        }
        h[n]=0;
        long ans=0;
        int sum=1;
        while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        }
        out.println(ans);
    } main {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] h=new int[n+1];
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        }
        h[n]=0;
        long ans=0;
        int sum=1;
        while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        }
        out.println(ans);
    } Scanner sc = new Scanner(in); sc new Scanner(in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h=new int[n+1]; h new int[n+1] n+1 n 1 for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i]=sc.nextInt();
        } {
            h[i]=sc.nextInt();
        } h[i]=sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc h[n]=0 h[n] h n 0 long ans=0; ans 0 int sum=1; sum 1 while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        } sum>0 sum 0 {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        } sum=0 sum 0 int c=0; c 0 for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            } {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            } if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                } h[i]>0 h[i] h i 0 {
                    h[i]--;
                    if(h[i+1]==0)c++;
                } h[i]-- h[i] h i if(h[i+1]==0)c++; h[i+1]==0 h[i+1] h i+1 i 1 0 c++ c sum+=h[i] sum h[i] h i ans+=c ans c out.println(ans) out.println out ans String[] $ $ public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] h=new int[n+1];
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        }
        h[n]=0;
        long ans=0;
        int sum=1;
        while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        }
        out.println(ans);
    }
} public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] h=new int[n+1];
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        }
        h[n]=0;
        long ans=0;
        int sum=1;
        while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        }
        out.println(ans);
    }
} Main
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] h=new int[n+1];
        for (int i = 0; i < n; i++) {
            h[i]=sc.nextInt();
        }
        h[n]=0;
        long ans=0;
        int sum=1;
        while (sum>0) {
            sum=0;
            int c=0;
            for (int i = 0; i < n; i++) {
                if(h[i]>0){
                    h[i]--;
                    if(h[i+1]==0)c++;
                }
                sum+=h[i];
            }
            ans+=c;
        }
        out.println(ans);
    }
}