import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    }
    static int counter = 0;
        private static void saiki(int[] hikisuu){
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        }
        //System.out.println(counter);
    } import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    }
    static int counter = 0;
        private static void saiki(int[] hikisuu){
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        }
        //System.out.println(counter);
    } Main static int counter = 0; counter 0 public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    } main {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int kosuu = sc.nextInt(); kosuu sc.nextInt() sc.nextInt sc int[] flower2 = new int[kosuu]; flower2 new int[kosuu] kosuu for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < kosuu i kosuu i++ i++ i {
            flower2[i] = sc.nextInt();
        } {
            flower2[i] = sc.nextInt();
        } flower2[i] = sc.nextInt() flower2[i] flower2 i sc.nextInt() sc.nextInt sc saiki(flower2) saiki flower2 System.out.println(counter) System.out.println System.out System System.out counter String[] args args private static void saiki(int[] hikisuu){
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        } saiki {
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        } int[] hairetu; hairetu int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            } int k = 0; int k = 0; k 0 k < hikisuu.length k hikisuu.length hikisuu hikisuu.length k++ k++ k {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            } {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            } int v = hikisuu[k]; v hikisuu[k] hikisuu k if (v < min) {
                    min = v;
                } v < min v min {
                    min = v;
                } min = v min v counter += min counter min for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            } int h = 0; int h = 0; h 0 h < hikisuu.length h hikisuu.length hikisuu hikisuu.length h++ h++ h {
                hikisuu[h] = hikisuu[h] - min;
            } {
                hikisuu[h] = hikisuu[h] - min;
            } hikisuu[h] = hikisuu[h] - min hikisuu[h] hikisuu h hikisuu[h] - min hikisuu[h] hikisuu h min int kioku = 0; kioku 0 for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            } int i = 0; int i = 0; i 0 i < hikisuu.length i hikisuu.length hikisuu hikisuu.length i++ i++ i {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            } {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            } if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } hikisuu[i] == 0 hikisuu[i] hikisuu i 0 {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    } kioku != i kioku i {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    } hairetu = Arrays.copyOfRange(hikisuu, kioku, i) hairetu Arrays.copyOfRange(hikisuu, kioku, i) Arrays.copyOfRange Arrays hikisuu kioku i saiki(hairetu) saiki hairetu kioku = i + 1 kioku i + 1 i 1 if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            } kioku != hikisuu.length kioku hikisuu.length hikisuu hikisuu.length {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            } hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length) hairetu Arrays.copyOfRange(hikisuu, kioku, hikisuu.length) Arrays.copyOfRange Arrays hikisuu kioku hikisuu.length hikisuu hikisuu.length saiki(hairetu) saiki hairetu int[] hikisuu hikisuu public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    }
    static int counter = 0;
        private static void saiki(int[] hikisuu){
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        }
        //System.out.println(counter);
    } public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    }
    static int counter = 0;
        private static void saiki(int[] hikisuu){
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        }
        //System.out.println(counter);
    } Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    }
    static int counter = 0;
        private static void saiki(int[] hikisuu){
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        }
        //System.out.println(counter);
    }