
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
//import org.apache.commons.lang3.StringUtils;
 
 
/**
 *
 * @author aj
 */
public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
} import java.io.BufferedInputStream; BufferedInputStream java.io import java.io.BufferedOutputStream; BufferedOutputStream java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.OutputStream; OutputStream java.io import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset import java.util.HashSet; HashSet java.util public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
} Main public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    } main {
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    } try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        } catch(Exception ex){
            ex.printStackTrace();
        } Exception ex {
            ex.printStackTrace();
        } ex.printStackTrace() ex.printStackTrace ex {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        } BufferedInputStream bf = new BufferedInputStream(System.in); bf new BufferedInputStream(System.in) BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8)); in new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8)) OutputStream out = new BufferedOutputStream ( System.out ); out new BufferedOutputStream ( System.out ) int n = Integer.parseInt(in.readLine()); n Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in String[] sh = in.readLine().split(" "); sh in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int[] h = new int[n]; h new int[n] n for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]); int i=0; int i=0; i 0 i<n i n i++ i++ i h[i] = Integer.parseInt(sh[i]); h[i] = Integer.parseInt(sh[i]) h[i] h i Integer.parseInt(sh[i]) Integer.parseInt Integer sh[i] sh i int sum = h[0]; sum h[0] h 0 for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            } int i=1; int i=1; i 1 i<n i n i++ i++ i {
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            } {
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            } if (h[i]>h[i-1]) sum += (h[i] - h[i-1]); h[i]>h[i-1] h[i] h i h[i-1] h i-1 i 1 sum += (h[i] - h[i-1]) sum (h[i] - h[i-1]) h[i] h i h[i-1] h i-1 i 1 out.write((sum+"\n").getBytes()) out.write out (sum+"\n").getBytes() (sum+"\n").getBytes (sum+"\n") sum "\n" out.flush() out.flush out String[] args args public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
} public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
} Main

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
//import org.apache.commons.lang3.StringUtils;
 
 
/**
 *
 * @author aj
 */
public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}