import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int N = sc.nextInt();
		int[] h = new int[N+1];
		h[0] = 0;
		for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        }	
		for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		}
		System.out.println(cnt);
    }
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int N = sc.nextInt();
		int[] h = new int[N+1];
		h[0] = 0;
		for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        }	
		for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		}
		System.out.println(cnt);
    }
} Main public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int N = sc.nextInt();
		int[] h = new int[N+1];
		h[0] = 0;
		for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        }	
		for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		}
		System.out.println(cnt);
    } main {
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int N = sc.nextInt();
		int[] h = new int[N+1];
		h[0] = 0;
		for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        }	
		for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		}
		System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int cnt = 0; cnt 0 int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] h = new int[N+1]; h new int[N+1] N+1 N 1 h[0] = 0 h[0] h 0 0 for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        } int i=1; int i=1; i 1 i<N+1 i N+1 N 1 i++ i++ i {
			h[i] = sc.nextInt();
        } {
			h[i] = sc.nextInt();
        } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		} int j=1; int j=1; j 1 j<N+1 j N+1 N 1 j++ j++ j {
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		} {
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		} if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			} h[j]-h[j-1]>=0 h[j]-h[j-1] h[j] h j h[j-1] h j-1 j 1 0 {
				cnt += (h[j]-h[j-1]);
			} cnt += (h[j]-h[j-1]) cnt (h[j]-h[j-1]) h[j] h j h[j-1] h j-1 j 1 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int N = sc.nextInt();
		int[] h = new int[N+1];
		h[0] = 0;
		for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        }	
		for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		}
		System.out.println(cnt);
    }
} public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int N = sc.nextInt();
		int[] h = new int[N+1];
		h[0] = 0;
		for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        }	
		for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		}
		System.out.println(cnt);
    }
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int N = sc.nextInt();
		int[] h = new int[N+1];
		h[0] = 0;
		for(int i=1;i<N+1;i++){
			h[i] = sc.nextInt();
        }	
		for(int j=1;j<N+1;j++){
			if(h[j]-h[j-1]>=0){
				cnt += (h[j]-h[j-1]);
			}
		}
		System.out.println(cnt);
    }
}