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];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    }
} 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];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    } 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 int count = 0; count 0 int max = 0; max 0 for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        } {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        } H[i] = sc.nextInt() H[i] H i sc.nextInt() sc.nextInt sc if (max < H[i]) max = H[i]; max < H[i] max H[i] H i max = H[i] max H[i] H i int[][] HN = new int[max][N]; HN new int[max][N] max N for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        } int i = 0; int i = 0; i 0 i < max i max i++ i++ i {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        } {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        } for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            } int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            } {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            } if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0; 0 < H[j] 0 H[j] H j {
                    HN[i][j] = 1;
                    H[j]--;
                } HN[i][j] = 1 HN[i][j] HN[i] HN i j 1 H[j]-- H[j] H j HN[i][j] = 0 HN[i][j] HN[i] HN i j 0 for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        } int[] line HN {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        } {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        } StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            } int i = 0; int i = 0; i 0 i < line.length i line.length line line.length i++ i++ i {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            } {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            } if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue; i == 0 && line[0] != 0 i == 0 i 0 line[0] != 0 line[0] line 0 0 sb.append(line[i]) sb.append sb line[i] line i if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue; 0 < i && line[i] != line[i-1] 0 < i 0 i line[i] != line[i-1] line[i] line i line[i-1] line i-1 i 1 sb.append(line[i]) sb.append sb line[i] line i continue; count += sb.toString().split("0").length count sb.toString().split("0").length sb.toString().split("0") sb.toString().split sb.toString() sb.toString sb "0" sb.toString().split("0").length System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    }
} public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    }
} 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];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    }
}