import java.util.Scanner;

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 ans = solve(n, h);
        System.out.println(ans);

    }

    private static int solve(int n, int[] h) {
        int maxLayer = 0;
        for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        }

        int[][] garden = new int[maxLayer][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        }
        return ans;
    }
} import java.util.Scanner; Scanner 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 ans = solve(n, h);
        System.out.println(ans);

    }

    private static int solve(int n, int[] h) {
        int maxLayer = 0;
        for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        }

        int[][] garden = new int[maxLayer][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        }
        return ans;
    }
} 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 ans = solve(n, h);
        System.out.println(ans);

    } 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 ans = solve(n, h);
        System.out.println(ans);

    } 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 ans = solve(n, h); ans solve(n, h) solve n h System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static int solve(int n, int[] h) {
        int maxLayer = 0;
        for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        }

        int[][] garden = new int[maxLayer][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        }
        return ans;
    } solve {
        int maxLayer = 0;
        for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        }

        int[][] garden = new int[maxLayer][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        }
        return ans;
    } int maxLayer = 0; maxLayer 0 for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            maxLayer = Math.max(maxLayer, h[i]);
        } {
            maxLayer = Math.max(maxLayer, h[i]);
        } maxLayer = Math.max(maxLayer, h[i]) maxLayer Math.max(maxLayer, h[i]) Math.max Math maxLayer h[i] h i int[][] garden = new int[maxLayer][n + 1]; garden new int[maxLayer][n + 1] maxLayer n + 1 n 1 for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        } {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        } for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            } int j = 0; int j = 0; j 0 j < h[i] j h[i] h i j++ j++ j {
                garden[j][i] = 1;
            } {
                garden[j][i] = 1;
            } garden[j][i] = 1 garden[j][i] garden[j] garden j i 1 int ans = 0; ans 0 for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        } int i = 0; int i = 0; i 0 i < maxLayer i maxLayer i++ i++ i {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        } {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        } for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            } {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            } int current = garden[i][j]; current garden[i][j] garden[i] garden i j int next = garden[i][j + 1]; next garden[i][j + 1] garden[i] garden i j + 1 j 1 if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                } current == 1 && next == 0 current == 1 current 1 next == 0 next 0 {
                    // 水の切れ目部分
                    ans++;
                } ans++ ans return ans; ans int n n int[] h h 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 ans = solve(n, h);
        System.out.println(ans);

    }

    private static int solve(int n, int[] h) {
        int maxLayer = 0;
        for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        }

        int[][] garden = new int[maxLayer][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        }
        return ans;
    }
} 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 ans = solve(n, h);
        System.out.println(ans);

    }

    private static int solve(int n, int[] h) {
        int maxLayer = 0;
        for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        }

        int[][] garden = new int[maxLayer][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        }
        return ans;
    }
} Main
import java.util.Scanner;

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 ans = solve(n, h);
        System.out.println(ans);

    }

    private static int solve(int n, int[] h) {
        int maxLayer = 0;
        for (int i = 0; i < n; i++) {
            maxLayer = Math.max(maxLayer, h[i]);
        }

        int[][] garden = new int[maxLayer][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < h[i]; j++) {
                garden[j][i] = 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < maxLayer; i++) {
            for (int j = 0; j < n; j++) {

                int current = garden[i][j];
                int next = garden[i][j + 1];
                if (current == 1 && next == 0) {
                    // 水の切れ目部分
                    ans++;
                }
            }
        }
        return ans;
    }
}
