import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        int sum=0,h_num=0;
        for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        }
        h_num+=List.get(0);
        for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        }
        System.out.println(h_num);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        int sum=0,h_num=0;
        for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        }
        h_num+=List.get(0);
        for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        }
        System.out.println(h_num);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        int sum=0,h_num=0;
        for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        }
        h_num+=List.get(0);
        for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        }
        System.out.println(h_num);
    } main {
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        int sum=0,h_num=0;
        for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        }
        h_num+=List.get(0);
        for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        }
        System.out.println(h_num);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N  = sc.nextInt(); N sc.nextInt() sc.nextInt sc ArrayList<Integer> List = new ArrayList<>(); List new ArrayList<>() int sum=0 sum 0 h_num=0; h_num 0 for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        } int a=0; int a=0; a 0 a<N a N a++ a++ a {
            List.add(sc.nextInt());
            sum+=List.get(a);
        } {
            List.add(sc.nextInt());
            sum+=List.get(a);
        } List.add(sc.nextInt()) List.add List sc.nextInt() sc.nextInt sc sum+=List.get(a) sum List.get(a) List.get List a h_num+=List.get(0) h_num List.get(0) List.get List 0 for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        } int a=1; int a=1; a 1 a<N a N a++ a++ a {
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        } {
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        } int num2=0; num2 0 if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1); List.get(a-1)<List.get(a) List.get(a-1) List.get List a-1 a 1 List.get(a) List.get List a num2 = List.get(a) - List.get(a-1) num2 List.get(a) - List.get(a-1) List.get(a) List.get List a List.get(a-1) List.get List a-1 a 1 h_num+=num2 h_num num2 System.out.println(h_num) System.out.println System.out System System.out h_num String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        int sum=0,h_num=0;
        for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        }
        h_num+=List.get(0);
        for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        }
        System.out.println(h_num);
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        int sum=0,h_num=0;
        for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        }
        h_num+=List.get(0);
        for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        }
        System.out.println(h_num);
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        int sum=0,h_num=0;
        for(int a=0;a<N;a++) {
            List.add(sc.nextInt());
            sum+=List.get(a);
        }
        h_num+=List.get(0);
        for(int a=1;a<N;a++){
            int num2=0;
            if(List.get(a-1)<List.get(a))num2 = List.get(a) - List.get(a-1);
            h_num+=num2;
        }
        System.out.println(h_num);
    }
}