import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i =0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    }

} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i =0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i =0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i =0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] h = new int[N]; h new int[N] N 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 int count = 0; count 0 for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        } ; true {
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        } {
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        } boolean flag = false; flag false for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            } {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            } if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                } h[i] > 0 h[i] h i 0 {
                    flag = true;
                    h[i]--;
                } flag = true flag true h[i]-- h[i] h i if ((flag && h[i] == 0)) {
                    break;
                } (flag && h[i] == 0) flag h[i] == 0 h[i] h i 0 {
                    break;
                } break; if (flag){
            count++;
          } flag {
            count++;
          } count++ count boolean check = true; check true for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            } {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            } if (h[i]>0) {
                    check = false;
                    break;
                } h[i]>0 h[i] h i 0 {
                    check = false;
                    break;
                } check = false check false break; if(check) {
                System.out.println(count);
                return;
            } check {
                System.out.println(count);
                return;
            } System.out.println(count) System.out.println System.out System System.out count return; String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i =0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i =0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    }

} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i =0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    }

}