import java.util.Scanner;

public class Main {

	private static int[] minSegment;

	private static int n;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] hList = new int[n];
		for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		}

		int count = 0;
		boolean allzero = false;

		while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		}


		System.out.println(count);

	}

}
 import java.util.Scanner; Scanner java.util public class Main {

	private static int[] minSegment;

	private static int n;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] hList = new int[n];
		for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		}

		int count = 0;
		boolean allzero = false;

		while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		}


		System.out.println(count);

	}

} Main private static int[] minSegment; minSegment private static int n; n public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] hList = new int[n];
		for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		}

		int count = 0;
		boolean allzero = false;

		while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		}


		System.out.println(count);

	} main {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] hList = new int[n];
		for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		}

		int count = 0;
		boolean allzero = false;

		while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		}


		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[] hList = new int[n]; hList new int[n] n for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			hList[i] = sc.nextInt();
		} {
			hList[i] = sc.nextInt();
		} hList[i] = sc.nextInt() hList[i] hList i sc.nextInt() sc.nextInt sc int count = 0; count 0 boolean allzero = false; allzero false while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		} !allzero allzero {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		} allzero = true allzero true boolean zeroFlg = true; zeroFlg true for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			} {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			} int h = hList[i]; h hList[i] hList i if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				} h > 0 h 0 {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} if(zeroFlg) {
						count++;
					} zeroFlg {
						count++;
					} count++ count hList[i] = h-1 hList[i] hList i h-1 h 1 zeroFlg = false zeroFlg false allzero = false allzero false {
					zeroFlg = true;
				} zeroFlg = true zeroFlg true System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	private static int[] minSegment;

	private static int n;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] hList = new int[n];
		for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		}

		int count = 0;
		boolean allzero = false;

		while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		}


		System.out.println(count);

	}

} public class Main {

	private static int[] minSegment;

	private static int n;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] hList = new int[n];
		for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		}

		int count = 0;
		boolean allzero = false;

		while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		}


		System.out.println(count);

	}

} Main
import java.util.Scanner;

public class Main {

	private static int[] minSegment;

	private static int n;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] hList = new int[n];
		for(int i = 0; i < n; i++) {
			hList[i] = sc.nextInt();
		}

		int count = 0;
		boolean allzero = false;

		while(!allzero) {
			allzero = true;
			boolean zeroFlg = true;
			for(int i = 0; i < n; i++) {
				int h = hList[i];

				if(h > 0) {
					if(zeroFlg) {
						count++;
					}
					hList[i] = h-1;
					zeroFlg = false;
					allzero = false;
				} else {
					zeroFlg = true;
				}
			}

		}


		System.out.println(count);

	}

}

