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

public class Main {
    private static int N;
    private static List<Integer> h = new ArrayList<>();

    static {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            h.add(Integer.parseInt(sc.next()));
        }
    }

    public static void main(String[] args) {
        System.out.println(rec(h));
    }

    private static int rec(List<Integer> l) {
        if (l == null || l.size() == 0) {
            return 0;
        }
        if (l.size() == 1) {
            return l.get(0);
        }
        int min = 101;

        for (int i : l) {
            min = Math.min(min, i);
        }

        int res = min;
        List<Integer> newL = new ArrayList<>();
        for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        }

        if (!newL.isEmpty()) {
            res += rec(newL);
        }

        return res;
    }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    private static int N;
    private static List<Integer> h = new ArrayList<>();

    static {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            h.add(Integer.parseInt(sc.next()));
        }
    }

    public static void main(String[] args) {
        System.out.println(rec(h));
    }

    private static int rec(List<Integer> l) {
        if (l == null || l.size() == 0) {
            return 0;
        }
        if (l.size() == 1) {
            return l.get(0);
        }
        int min = 101;

        for (int i : l) {
            min = Math.min(min, i);
        }

        int res = min;
        List<Integer> newL = new ArrayList<>();
        for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        }

        if (!newL.isEmpty()) {
            res += rec(newL);
        }

        return res;
    }
} Main private static int N; N private static List<Integer> h = new ArrayList<>(); h new ArrayList<>() public static void main(String[] args) {
        System.out.println(rec(h));
    } main {
        System.out.println(rec(h));
    } System.out.println(rec(h)) System.out.println System.out System System.out rec(h) rec h String[] args args private static int rec(List<Integer> l) {
        if (l == null || l.size() == 0) {
            return 0;
        }
        if (l.size() == 1) {
            return l.get(0);
        }
        int min = 101;

        for (int i : l) {
            min = Math.min(min, i);
        }

        int res = min;
        List<Integer> newL = new ArrayList<>();
        for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        }

        if (!newL.isEmpty()) {
            res += rec(newL);
        }

        return res;
    } rec {
        if (l == null || l.size() == 0) {
            return 0;
        }
        if (l.size() == 1) {
            return l.get(0);
        }
        int min = 101;

        for (int i : l) {
            min = Math.min(min, i);
        }

        int res = min;
        List<Integer> newL = new ArrayList<>();
        for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        }

        if (!newL.isEmpty()) {
            res += rec(newL);
        }

        return res;
    } if (l == null || l.size() == 0) {
            return 0;
        } l == null || l.size() == 0 l == null l null l.size() == 0 l.size() l.size l 0 {
            return 0;
        } return 0; 0 if (l.size() == 1) {
            return l.get(0);
        } l.size() == 1 l.size() l.size l 1 {
            return l.get(0);
        } return l.get(0); l.get(0) l.get l 0 int min = 101; min 101 for (int i : l) {
            min = Math.min(min, i);
        } int i l {
            min = Math.min(min, i);
        } {
            min = Math.min(min, i);
        } min = Math.min(min, i) min Math.min(min, i) Math.min Math min i int res = min; res min List<Integer> newL = new ArrayList<>(); newL new ArrayList<>() for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        } int i l {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        } {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        } int v = i - min; v i - min i min if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            } v != 0 v 0 {
                newL.add(v);
            } newL.add(v) newL.add newL v {
                res += rec(newL);
                newL = new ArrayList<>();
            } res += rec(newL) res rec(newL) rec newL newL = new ArrayList<>() newL new ArrayList<>() if (!newL.isEmpty()) {
            res += rec(newL);
        } !newL.isEmpty() newL.isEmpty() newL.isEmpty newL {
            res += rec(newL);
        } res += rec(newL) res rec(newL) rec newL return res; res List<Integer> l l public class Main {
    private static int N;
    private static List<Integer> h = new ArrayList<>();

    static {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            h.add(Integer.parseInt(sc.next()));
        }
    }

    public static void main(String[] args) {
        System.out.println(rec(h));
    }

    private static int rec(List<Integer> l) {
        if (l == null || l.size() == 0) {
            return 0;
        }
        if (l.size() == 1) {
            return l.get(0);
        }
        int min = 101;

        for (int i : l) {
            min = Math.min(min, i);
        }

        int res = min;
        List<Integer> newL = new ArrayList<>();
        for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        }

        if (!newL.isEmpty()) {
            res += rec(newL);
        }

        return res;
    }
} public class Main {
    private static int N;
    private static List<Integer> h = new ArrayList<>();

    static {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            h.add(Integer.parseInt(sc.next()));
        }
    }

    public static void main(String[] args) {
        System.out.println(rec(h));
    }

    private static int rec(List<Integer> l) {
        if (l == null || l.size() == 0) {
            return 0;
        }
        if (l.size() == 1) {
            return l.get(0);
        }
        int min = 101;

        for (int i : l) {
            min = Math.min(min, i);
        }

        int res = min;
        List<Integer> newL = new ArrayList<>();
        for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        }

        if (!newL.isEmpty()) {
            res += rec(newL);
        }

        return res;
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static int N;
    private static List<Integer> h = new ArrayList<>();

    static {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            h.add(Integer.parseInt(sc.next()));
        }
    }

    public static void main(String[] args) {
        System.out.println(rec(h));
    }

    private static int rec(List<Integer> l) {
        if (l == null || l.size() == 0) {
            return 0;
        }
        if (l.size() == 1) {
            return l.get(0);
        }
        int min = 101;

        for (int i : l) {
            min = Math.min(min, i);
        }

        int res = min;
        List<Integer> newL = new ArrayList<>();
        for (int i : l) {
            int v = i - min;
            if (v != 0) {
                newL.add(v);
            } else {
                res += rec(newL);
                newL = new ArrayList<>();
            }
        }

        if (!newL.isEmpty()) {
            res += rec(newL);
        }

        return res;
    }
}
