import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] hs = new int[n + 2];
        hs[0] = hs[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        }

        boolean f = true;
        int ans = 0;
        while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        }
        System.out.println(ans);
    }
} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] hs = new int[n + 2];
        hs[0] = hs[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        }

        boolean f = true;
        int ans = 0;
        while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    } main {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    } try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        } {
            new Main().solve(sc);
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) new Main().solve(sc) new Main().solve new Main() sc String[] args args void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] hs = new int[n + 2];
        hs[0] = hs[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        }

        boolean f = true;
        int ans = 0;
        while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        }
        System.out.println(ans);
    } solve {
        int n = sc.nextInt();
        int[] hs = new int[n + 2];
        hs[0] = hs[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        }

        boolean f = true;
        int ans = 0;
        while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        }
        System.out.println(ans);
    } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] hs = new int[n + 2]; hs new int[n + 2] n + 2 n 2 hs[0] = hs[n + 1] = 0 hs[0] hs 0 hs[n + 1] = 0 hs[n + 1] hs n + 1 n 1 0 for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            hs[i] = sc.nextInt();
        } {
            hs[i] = sc.nextInt();
        } hs[i] = sc.nextInt() hs[i] hs i sc.nextInt() sc.nextInt sc boolean f = true; f true int ans = 0; ans 0 while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        } f {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        } f = false f false for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            } int i = 0; int i = 0; i 0 i <= n i n i++ i++ i {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            } {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            } if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } hs[i] == 0 hs[i] hs i 0 {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } if (hs[i + 1] > 0) {
                        ans++;
                    } hs[i + 1] > 0 hs[i + 1] hs i + 1 i 1 0 {
                        ans++;
                    } ans++ ans continue; hs[i]-- hs[i] hs i f = true f true System.out.println(ans) System.out.println System.out System System.out ans Scanner sc sc public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] hs = new int[n + 2];
        hs[0] = hs[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        }

        boolean f = true;
        int ans = 0;
        while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] hs = new int[n + 2];
        hs[0] = hs[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        }

        boolean f = true;
        int ans = 0;
        while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] hs = new int[n + 2];
        hs[0] = hs[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            hs[i] = sc.nextInt();
        }

        boolean f = true;
        int ans = 0;
        while (f) {
            f = false;
            for (int i = 0; i <= n; i++) {
                if (hs[i] == 0) {
                    if (hs[i + 1] > 0) {
                        ans++;
                    }
                    continue;
                } 
                
                hs[i]--;
                f = true;
            }
        }
        System.out.println(ans);
    }
}
