import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] h =new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;

		while(true){
			boolean cc = true;
			for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			}
			if(cc){
				break;
			}

			int l = 0;			//左端
			while(h[l] == 0){
				l++;
			}
			int r = l+1;			//右端
			if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			}

			for(int x = l;x < r;x++){			//-1
				h[x]--;
			}
			ans++;



		}
		System.out.println(ans);

	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}
 import java.util.Scanner; Scanner java.util class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] h =new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;

		while(true){
			boolean cc = true;
			for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			}
			if(cc){
				break;
			}

			int l = 0;			//左端
			while(h[l] == 0){
				l++;
			}
			int r = l+1;			//右端
			if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			}

			for(int x = l;x < r;x++){			//-1
				h[x]--;
			}
			ans++;



		}
		System.out.println(ans);

	}


} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] h =new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;

		while(true){
			boolean cc = true;
			for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			}
			if(cc){
				break;
			}

			int l = 0;			//左端
			while(h[l] == 0){
				l++;
			}
			int r = l+1;			//右端
			if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			}

			for(int x = l;x < r;x++){			//-1
				h[x]--;
			}
			ans++;



		}
		System.out.println(ans);

	} main {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] h =new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;

		while(true){
			boolean cc = true;
			for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			}
			if(cc){
				break;
			}

			int l = 0;			//左端
			while(h[l] == 0){
				l++;
			}
			int r = l+1;			//右端
			if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			}

			for(int x = l;x < r;x++){			//-1
				h[x]--;
			}
			ans++;



		}
		System.out.println(ans);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h =new int[n]; h new int[n] n for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
		} {
			h[i] = sc.nextInt();
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int ans = 0; ans 0 while(true){
			boolean cc = true;
			for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			}
			if(cc){
				break;
			}

			int l = 0;			//左端
			while(h[l] == 0){
				l++;
			}
			int r = l+1;			//右端
			if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			}

			for(int x = l;x < r;x++){			//-1
				h[x]--;
			}
			ans++;



		} true {
			boolean cc = true;
			for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			}
			if(cc){
				break;
			}

			int l = 0;			//左端
			while(h[l] == 0){
				l++;
			}
			int r = l+1;			//右端
			if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			}

			for(int x = l;x < r;x++){			//-1
				h[x]--;
			}
			ans++;



		} boolean cc = true; cc true for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {			//チェック
				if(h[i] != 0){
					cc = false;
				}
			} {			//チェック
				if(h[i] != 0){
					cc = false;
				}
			} if(h[i] != 0){
					cc = false;
				} h[i] != 0 h[i] h i 0 {
					cc = false;
				} cc = false cc false if(cc){
				break;
			} cc {
				break;
			} break; int l = 0; l 0 while(h[l] == 0){
				l++;
			} h[l] == 0 h[l] h l 0 {
				l++;
			} l++ l int r = l+1; r l+1 l 1 if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			} r < n r n {
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			} while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				} h[r] != 0 h[r] h r 0 {
					r++;
					if(r >= n){
						break;
					}
				} r++ r if(r >= n){
						break;
					} r >= n r n {
						break;
					} break; for(int x = l;x < r;x++){			//-1
				h[x]--;
			} int x = l; int x = l; x l x < r x r x++ x++ x {			//-1
				h[x]--;
			} {			//-1
				h[x]--;
			} h[x]-- h[x] h x ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
} Pair int from;		//p from int end;		//y end int num; num int bango; bango @Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	} compareTo {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	} Pair otherpair = (Pair)other; otherpair (Pair)other return from - otherpair.from; from - otherpair.from from otherpair.from otherpair otherpair.from Object other other Comparable
import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] h =new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;

		while(true){
			boolean cc = true;
			for(int i = 0;i < n;i++){			//チェック
				if(h[i] != 0){
					cc = false;
				}
			}
			if(cc){
				break;
			}

			int l = 0;			//左端
			while(h[l] == 0){
				l++;
			}
			int r = l+1;			//右端
			if(r < n){
				while( h[r] != 0 ){
					r++;
					if(r >= n){
						break;
					}
				}
			}

			for(int x = l;x < r;x++){			//-1
				h[x]--;
			}
			ans++;



		}
		System.out.println(ans);

	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}

