import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        }
        int[] hc = new int[N];
        int ans = 0;
        while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        }
        int[] hc = new int[N];
        int ans = 0;
        while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        }
        System.out.println(ans);
    }
} Main public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        }
        int[] hc = new int[N];
        int ans = 0;
        while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        }
        System.out.println(ans);
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        }
        int[] hc = new int[N];
        int ans = 0;
        while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        }
        System.out.println(ans);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] h = new int[N]; h new int[N] N for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < h.length i h.length h h.length i++ i++ i {
            h[i] = scanner.nextInt();
        } {
            h[i] = scanner.nextInt();
        } h[i] = scanner.nextInt() h[i] h i scanner.nextInt() scanner.nextInt scanner int[] hc = new int[N]; hc new int[N] N int ans = 0; ans 0 while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        } true {
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        } int count = 0; count 0 boolean section = false; section false for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            } int i = 0; int i = 0; i 0 i < h.length i h.length h h.length i++ i++ i {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            } {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            } if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                } hc[i] < h[i] hc[i] hc i h[i] h i {
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                } if(!section) count++; !section section count++ count section = true section true hc[i] ++ hc[i] hc i {
                    section = false;
                } section = false section false ans += count ans count if(count == 0) break; count == 0 count 0 break; System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        }
        int[] hc = new int[N];
        int ans = 0;
        while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        }
        System.out.println(ans);
    }
} public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        }
        int[] hc = new int[N];
        int ans = 0;
        while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        }
        System.out.println(ans);
    }
} Main
import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = scanner.nextInt();
        }
        int[] hc = new int[N];
        int ans = 0;
        while(true){
            int count = 0;
            boolean section = false;
            for (int i = 0; i < h.length; i++) {
                if(hc[i] < h[i]){
                    if(!section) count++;
                    section = true;
                    hc[i] ++;
                }else{
                    section = false;
                }
            }
            ans += count;
            if(count == 0) break;
        }
        System.out.println(ans);
    }
}