import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int h[] = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int ans = 0;
        boolean f = true;
        while (f) {
            f = false;
            boolean m = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int h[] = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int ans = 0;
        boolean f = true;
        while (f) {
            f = false;
            boolean m = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int h[] = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int ans = 0;
        boolean f = true;
        while (f) {
            f = false;
            boolean m = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int h[] = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int ans = 0;
        boolean f = true;
        while (f) {
            f = false;
            boolean m = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int h[] = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] = Integer.parseInt(sc.next());
        } {
            h[i] = Integer.parseInt(sc.next());
        } h[i] = Integer.parseInt(sc.next()) h[i] h i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int ans = 0; ans 0 boolean f = true; f true while (f) {
            f = false;
            boolean m = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            }
        } f {
            f = false;
            boolean m = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            }
        } f = false f false boolean m = true; m true for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            } {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            } if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                } h[i] > 0 h[i] h i 0 {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } h[i]-- h[i] h i ans += (m) ? 1 : 0 ans (m) ? 1 : 0 (m) 1 0 f = true f true m = false m false {
                    m = true;
                } m = true m true System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int h[] = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int ans = 0;
        boolean f = true;
        while (f) {
            f = false;
            boolean m = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    ans += (m) ? 1 : 0;
                    f = true;
                    m = false;
                } else {
                    m = true;
                }
            }
        }
        System.out.println(ans);
    }
}