import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        }
    }
} Main public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        }
    } main {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        }
    } try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        } {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        } Scanner scanner = new Scanner(System.in) Scanner scanner = new Scanner(System.in) new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] As = new int[N]; As new int[N] N for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                As[i] = scanner.nextInt();
            } {
                As[i] = scanner.nextInt();
            } As[i] = scanner.nextInt() As[i] As i scanner.nextInt() scanner.nextInt scanner int sum = 0; sum 0 int current = 0; current 0 for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            } {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            } if (As[i] > current) {
                    sum += As[i] - current;
                } As[i] > current As[i] As i current {
                    sum += As[i] - current;
                } sum += As[i] - current sum As[i] - current As[i] As i current current = As[i] current As[i] As i System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] As = new int[N];
            for (int i = 0; i < N; i++) {
                As[i] = scanner.nextInt();
            }
            int sum = 0;
            int current = 0;
            for (int i = 0; i < N; i++) {
                if (As[i] > current) {
                    sum += As[i] - current;
                }
                current = As[i];
            }
            System.out.println(sum);
        }
    }
}
