import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = 0;
        int[] list = new int[a];
        for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        }
        int ans = 0;
        for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        }
        System.out.println(ans);
    }
} import java.awt.List; List java.awt import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = 0;
        int[] list = new int[a];
        for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        }
        int ans = 0;
        for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = 0;
        int[] list = new int[a];
        for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        }
        int ans = 0;
        for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = 0;
        int[] list = new int[a];
        for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        }
        int ans = 0;
        for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int max = 0; max 0 int[] list = new int[a]; list new int[a] a for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        } int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        } {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        } list[i] = sc.nextInt() list[i] list i sc.nextInt() sc.nextInt sc if(list[i] > max) {
                max = list[i];
            } list[i] > max list[i] list i max {
                max = list[i];
            } max = list[i] max list[i] list i int ans = 0; ans 0 for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        } int i = 0; int i = 0; i 0 i < max i max i++ i++ i {
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        } {
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        } boolean flg = false; flg false for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            } int j = 0; int j = 0; j 0 j < a j a j++ j++ j {
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            } {
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            } if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                } list[j] > i && !flg list[j] > i list[j] list j i !flg flg {
                    ans++;
                    flg = true;
                } ans++ ans flg = true flg true if(list[j] <= i) {
                    flg = false;
                } list[j] <= i list[j] list j i {
                    flg = false;
                } flg = false flg false 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 sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = 0;
        int[] list = new int[a];
        for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        }
        int ans = 0;
        for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = 0;
        int[] list = new int[a];
        for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        }
        int ans = 0;
        for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        }
        System.out.println(ans);
    }
} Main
import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = 0;
        int[] list = new int[a];
        for (int i = 0; i < a; i++) {
            list[i] = sc.nextInt();
            if(list[i] > max) {
                max = list[i];
            }
        }
        int ans = 0;
        for(int i = 0;i < max;i++){
            boolean flg = false;
            for(int j = 0; j < a; j++){
                if(list[j] > i && !flg){
                    ans++;
                    flg = true;
                } else if(list[j] <= i) {
                    flg = false;
                }
            }
        }
        System.out.println(ans);
    }
}
