import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        }
    }

    //左端取得
    static int getLeft(int[] h, int N){
        int l = 0;
        for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        }
        return l;
    }
    //右端取得
    static int getRight(int[] h, int N, int l){
        int r = 0;
        for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        }
        return r;
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        }
    }

    //左端取得
    static int getLeft(int[] h, int N){
        int l = 0;
        for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        }
        return l;
    }
    //右端取得
    static int getRight(int[] h, int N, int l){
        int r = 0;
        for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        }
        return r;
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        }
    } main {
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        } {
            scan.close();
        } scan.close() scan.close scan {
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        } int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] h_ = new int [N]; h_ new int [N] N int sum = 0; sum 0 for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                sum += h_[i] = scan.nextInt();
            } {
                sum += h_[i] = scan.nextInt();
            } sum += h_[i] = scan.nextInt() sum h_[i] = scan.nextInt() h_[i] h_ i scan.nextInt() scan.nextInt scan int count = 0; count 0 while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            } sum != 0 sum 0 {
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            } int l = getLeft(h_, N); l getLeft(h_, N) getLeft h_ N int r = getRight(h_, N, l); r getRight(h_, N, l) getRight h_ N l for(int i = l; i <= r; i++){
                    h_[i]--;
                } int i = l; int i = l; i l i <= r i r i++ i++ i {
                    h_[i]--;
                } {
                    h_[i]--;
                } h_[i]-- h_[i] h_ i sum -= r-l+1 sum r-l+1 r-l r l 1 count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args //左端取得
    static int getLeft(int[] h, int N){
        int l = 0;
        for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        }
        return l;
    } getLeft {
        int l = 0;
        for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        }
        return l;
    } int l = 0; l 0 for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        } {
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        } if(h[i] != 0){
                l = i;
                break;
            }else{
            } h[i] != 0 h[i] h i 0 {
                l = i;
                break;
            } l = i l i break; {
            } return l; l int[] h h int N N //右端取得
    static int getRight(int[] h, int N, int l){
        int r = 0;
        for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        }
        return r;
    } getRight {
        int r = 0;
        for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        }
        return r;
    } int r = 0; r 0 for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        } int i = l; int i = l; i l i < N i N i++ i++ i {
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        } {
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        } if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            } h[i] == 0 h[i] h i 0 {
                r = i-1;
                break;
            } r = i-1 r i-1 i 1 break; if(i == N-1){
                r = N-1;
            } i == N-1 i N-1 N 1 {
                r = N-1;
            } r = N-1 r N-1 N 1 return r; r int[] h h int N N int l l public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        }
    }

    //左端取得
    static int getLeft(int[] h, int N){
        int l = 0;
        for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        }
        return l;
    }
    //右端取得
    static int getRight(int[] h, int N, int l){
        int r = 0;
        for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        }
        return r;
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        }
    }

    //左端取得
    static int getLeft(int[] h, int N){
        int l = 0;
        for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        }
        return l;
    }
    //右端取得
    static int getRight(int[] h, int N, int l){
        int r = 0;
        for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        }
        return r;
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] h_ = new int [N];
            int sum = 0;
            for(int i = 0; i < N; i++){
                sum += h_[i] = scan.nextInt();
            }

            int count = 0;
            while(sum != 0){
                int l = getLeft(h_, N);
                int r = getRight(h_, N, l);
                for(int i = l; i <= r; i++){
                    h_[i]--;
                }
                sum -= r-l+1;
                count++;
            }

            System.out.println(count);

        }finally{
            scan.close();
        }
    }

    //左端取得
    static int getLeft(int[] h, int N){
        int l = 0;
        for(int i = 0; i < N; i++){
            if(h[i] != 0){
                l = i;
                break;
            }else{
            }
        }
        return l;
    }
    //右端取得
    static int getRight(int[] h, int N, int l){
        int r = 0;
        for(int i = l; i < N; i++){
            if(h[i] == 0){
                r = i-1;
                break;
            }else if(i == N-1){
                r = N-1;
            }
        }
        return r;
    }
}
