import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    }
} import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    }
} Main public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    } main {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    } final Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) final int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner final int[] h = new int[N]; h new int[N] N final int maxHeight; maxHeight {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        } int maxHeightCandidate = 0; maxHeightCandidate 0 for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            } int k = 1; int k = 1; k 1 k <= N k N k++ k++ k {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            } {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            } h[k - 1] = scanner.nextInt() h[k - 1] h k - 1 k 1 scanner.nextInt() scanner.nextInt scanner if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                } maxHeightCandidate < h[k - 1] maxHeightCandidate h[k - 1] h k - 1 k 1 {
                    maxHeightCandidate = h[k - 1];
                } maxHeightCandidate = h[k - 1] maxHeightCandidate h[k - 1] h k - 1 k 1 maxHeight = maxHeightCandidate maxHeight maxHeightCandidate int totalCount = 0; totalCount 0 for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        } int height = 1; int height = 1; height 1 height <= maxHeight height maxHeight height++ height++ height {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        } {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        } int countPerHeight = 0; countPerHeight 0 boolean exists = false; exists false for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            } int k = 1; int k = 1; k 1 k <= N k N k++ k++ k {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            } {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            } if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                } exists {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } if (h[k - 1] < height) {
                        exists = false;
                    } h[k - 1] < height h[k - 1] h k - 1 k 1 height {
                        exists = false;
                    } exists = false exists false {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                } if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    } h[k - 1] >= height h[k - 1] h k - 1 k 1 height {
                        exists = true;
                        countPerHeight++;
                    } exists = true exists true countPerHeight++ countPerHeight totalCount += countPerHeight totalCount countPerHeight System.out.println(totalCount) System.out.println System.out System System.out totalCount String[] args args public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    }
} public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    }
} Main
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    }
}
