import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	}
        
    	System.out.println(count);
        
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	}
        
    	System.out.println(count);
        
    }
} Main public static void main(String[] args) throws Exception {
        
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	}
        
    	System.out.println(count);
        
    } main {
        
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	}
        
    	System.out.println(count);
        
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int count=0; count 0 int[] h=new int[n]; h new int[n] n for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	} int c=0; int c=0; c 0 c<n c n c++ c++ c {
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	} {
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	} h[c]=sc.nextInt() h[c] h c sc.nextInt() sc.nextInt sc if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            } c==0 c 0 {
                
                count+=h[c];
                
            } count+=h[c] count h[c] h c if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            } h[c-1]<h[c] h[c-1] h c-1 c 1 h[c] h c {
                
                count+=h[c]-h[c-1];
            } count+=h[c]-h[c-1] count h[c]-h[c-1] h[c] h c h[c-1] h c-1 c 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	}
        
    	System.out.println(count);
        
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	}
        
    	System.out.println(count);
        
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
		    
    		h[c]=sc.nextInt();
            if(c==0){
                
                count+=h[c];
                
            }else if(h[c-1]<h[c]){
                
                count+=h[c]-h[c-1];
            }
    	}
        
    	System.out.println(count);
        
    }
}
