import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String[] str = bf.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        }
        int answer = h[0];
        for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        }
        System.out.println(answer);
    }
} import java.io.*; io.* java public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String[] str = bf.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        }
        int answer = h[0];
        for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        }
        System.out.println(answer);
    }
} Main public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String[] str = bf.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        }
        int answer = h[0];
        for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        }
        System.out.println(answer);
    } main {
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String[] str = bf.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        }
        int answer = h[0];
        for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        }
        System.out.println(answer);
    } BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in)); bf new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(bf.readLine()); N Integer.parseInt(bf.readLine()) Integer.parseInt Integer bf.readLine() bf.readLine bf String[] str = bf.readLine().split(" "); str bf.readLine().split(" ") bf.readLine().split bf.readLine() bf.readLine bf " " int[] h = new int[N]; h new int[N] N for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            h[i] = Integer.parseInt(str[i]);
        } {
            h[i] = Integer.parseInt(str[i]);
        } h[i] = Integer.parseInt(str[i]) h[i] h i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i int answer = h[0]; answer h[0] h 0 for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        } {
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        } int value = h[i+1] -h[i]; value h[i+1] -h[i] h[i+1] h i+1 i 1 h[i] h i if(value > 0){
                answer += value;
            } value > 0 value 0 {
                answer += value;
            } answer += value answer value System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String[] str = bf.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        }
        int answer = h[0];
        for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        }
        System.out.println(answer);
    }
} public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String[] str = bf.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        }
        int answer = h[0];
        for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        }
        System.out.println(answer);
    }
} Main
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String[] str = bf.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = Integer.parseInt(str[i]);
        }
        int answer = h[0];
        for(int i = 0; i < N-1; i++){
            int value = h[i+1] -h[i];
            if(value > 0){
                answer += value;
            }
        }
        System.out.println(answer);
    }
}