import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] flowerInfo = new int[n+1];
		for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		}
		int answer = 0;
		while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		}
		System.out.println(answer);
	}

	private static boolean isEnd(int[] flowerInfo) {
		boolean endFlg = true;
		for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		}
		return true;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] flowerInfo = new int[n+1];
		for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		}
		int answer = 0;
		while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		}
		System.out.println(answer);
	}

	private static boolean isEnd(int[] flowerInfo) {
		boolean endFlg = true;
		for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		}
		return true;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] flowerInfo = new int[n+1];
		for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		}
		int answer = 0;
		while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		}
		System.out.println(answer);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] flowerInfo = new int[n+1];
		for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		}
		int answer = 0;
		while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		}
		System.out.println(answer);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] flowerInfo = new int[n+1]; flowerInfo new int[n+1] n+1 n 1 for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		} int i=1; int i=1; i 1 i <= n i n i++ i++ i {
			flowerInfo[i] = sc.nextInt();
		} {
			flowerInfo[i] = sc.nextInt();
		} flowerInfo[i] = sc.nextInt() flowerInfo[i] flowerInfo i sc.nextInt() sc.nextInt sc int answer = 0; answer 0 while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		} !isEnd(flowerInfo) isEnd(flowerInfo) isEnd flowerInfo {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		} for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			} int i =1; int i =1; i 1 i < flowerInfo.length i flowerInfo.length flowerInfo flowerInfo.length i++ i++ i {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			} {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			} if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				} flowerInfo[i] != 0 flowerInfo[i] flowerInfo i 0 {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				} int left = i; left i int right = i; right i int mizuyari = 0; mizuyari 0 for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					} int j = left; int j = left; j left j < flowerInfo.length j flowerInfo.length flowerInfo flowerInfo.length j++ j++ j {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					} {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					} if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						} flowerInfo[left] > flowerInfo[j] flowerInfo[left] flowerInfo left flowerInfo[j] flowerInfo j {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						} right = j-1 right j-1 j 1 mizuyari = flowerInfo[left] - flowerInfo[j] mizuyari flowerInfo[left] - flowerInfo[j] flowerInfo[left] flowerInfo left flowerInfo[j] flowerInfo j break; if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						} j == n j n {
							right = j;
							mizuyari = flowerInfo[left];
						} right = j right j mizuyari = flowerInfo[left] mizuyari flowerInfo[left] flowerInfo left for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					} int k = left; int k = left; k left k <=right k right k++ k++ k {
						flowerInfo[k] -= mizuyari;
					} {
						flowerInfo[k] -= mizuyari;
					} flowerInfo[k] -= mizuyari flowerInfo[k] flowerInfo k mizuyari answer += mizuyari answer mizuyari break; System.out.println(answer) System.out.println System.out System System.out answer String[] args args private static boolean isEnd(int[] flowerInfo) {
		boolean endFlg = true;
		for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		}
		return true;
	} isEnd {
		boolean endFlg = true;
		for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		}
		return true;
	} boolean endFlg = true; endFlg true for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		} int i =1; int i =1; i 1 i < flowerInfo.length i flowerInfo.length flowerInfo flowerInfo.length i++ i++ i {
			if(flowerInfo[i] != 0) {
				return false;
			}
		} {
			if(flowerInfo[i] != 0) {
				return false;
			}
		} if(flowerInfo[i] != 0) {
				return false;
			} flowerInfo[i] != 0 flowerInfo[i] flowerInfo i 0 {
				return false;
			} return false; false return true; true int[] flowerInfo flowerInfo public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] flowerInfo = new int[n+1];
		for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		}
		int answer = 0;
		while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		}
		System.out.println(answer);
	}

	private static boolean isEnd(int[] flowerInfo) {
		boolean endFlg = true;
		for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		}
		return true;
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] flowerInfo = new int[n+1];
		for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		}
		int answer = 0;
		while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		}
		System.out.println(answer);
	}

	private static boolean isEnd(int[] flowerInfo) {
		boolean endFlg = true;
		for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		}
		return true;
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] flowerInfo = new int[n+1];
		for(int i=1;i <= n;i++) {
			flowerInfo[i] = sc.nextInt();
		}
		int answer = 0;
		while(!isEnd(flowerInfo)) {
			for(int i =1;i < flowerInfo.length;i++) {
				if(flowerInfo[i] != 0) {
					int left = i;
					int right = i;
					int mizuyari = 0;
					for(int j = left;j < flowerInfo.length;j++) {
						if(flowerInfo[left] > flowerInfo[j]) {
							right = j-1;
							mizuyari = flowerInfo[left] - flowerInfo[j];
							break;
						}
						if(j == n) {
							right = j;
							mizuyari = flowerInfo[left];
						}
					}
					for(int k = left;k <=right;k++) {
						flowerInfo[k] -= mizuyari;
					}
					answer += mizuyari;
					break;
				}
			}
		}
		System.out.println(answer);
	}

	private static boolean isEnd(int[] flowerInfo) {
		boolean endFlg = true;
		for(int i =1;i < flowerInfo.length;i++) {
			if(flowerInfo[i] != 0) {
				return false;
			}
		}
		return true;
	}
}