import java.util.Scanner;


public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("4 1 2 2 1");
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        boolean flag = true;
        int cnt = 0;

        while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        }
        System.out.println(cnt);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("4 1 2 2 1");
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        boolean flag = true;
        int cnt = 0;

        while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        }
        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("4 1 2 2 1");
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        boolean flag = true;
        int cnt = 0;

        while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        }
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("4 1 2 2 1");
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        boolean flag = true;
        int cnt = 0;

        while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] h = new int[n]; h new int[n] n for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            h[i] = Integer.parseInt(sc.next());
        } {
            h[i] = Integer.parseInt(sc.next());
        } h[i] = Integer.parseInt(sc.next()) h[i] h i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc boolean flag = true; flag true int cnt = 0; cnt 0 while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        } flag {
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        } flag = false flag false boolean prevPlus = false; prevPlus false for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            } {
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            } if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                } prevPlus {
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                } if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    } h[i]>0 h[i] h i 0 {
                        h[i]--;
                        continue;
                    } h[i]-- h[i] h i continue; {
                        prevPlus = false;
                        continue;
                    } prevPlus = false prevPlus false continue; {
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                } if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    } h[i]>0 h[i] h i 0 {
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    } flag = true flag true prevPlus = true prevPlus true cnt++ cnt h[i]-- h[i] h i continue; {
                        continue;
                    } continue; System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("4 1 2 2 1");
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        boolean flag = true;
        int cnt = 0;

        while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        }
        System.out.println(cnt);
    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("4 1 2 2 1");
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        boolean flag = true;
        int cnt = 0;

        while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        }
        System.out.println(cnt);
    }
} Main
import java.util.Scanner;


public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("4 1 2 2 1");
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        boolean flag = true;
        int cnt = 0;

        while(flag){
            flag = false;
            boolean prevPlus = false;
            for(int i=0;i<n;i++){
                if(prevPlus){
                    if(h[i]>0){
                        h[i]--;
                        continue;
                    }else{
                        prevPlus = false;
                        continue;
                    }
                }else{
                    if(h[i]>0){
                        flag = true;
                        prevPlus = true;
                        cnt++;
                        h[i]--;
                        continue;
                    
                    }else{
                        continue;
                    }
                }
            }
        }
        System.out.println(cnt);
    }
}