import 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 + 2];
		int answer = 0;
		for (int i = 1; i <= n; i++) {
			h[i] = sc.nextInt();
		}
		int flag = 0;
		int flag2 = 0;

		int hoge = 0;
		int i = 1;
		while (flag == 0) {
			while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			}
			if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			}
		}
		System.out.print(answer);
		sc.close();
	}
} import java.util.*; util.* java class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n + 2];
		int answer = 0;
		for (int i = 1; i <= n; i++) {
			h[i] = sc.nextInt();
		}
		int flag = 0;
		int flag2 = 0;

		int hoge = 0;
		int i = 1;
		while (flag == 0) {
			while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			}
			if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			}
		}
		System.out.print(answer);
		sc.close();
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n + 2];
		int answer = 0;
		for (int i = 1; i <= n; i++) {
			h[i] = sc.nextInt();
		}
		int flag = 0;
		int flag2 = 0;

		int hoge = 0;
		int i = 1;
		while (flag == 0) {
			while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			}
			if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			}
		}
		System.out.print(answer);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n + 2];
		int answer = 0;
		for (int i = 1; i <= n; i++) {
			h[i] = sc.nextInt();
		}
		int flag = 0;
		int flag2 = 0;

		int hoge = 0;
		int i = 1;
		while (flag == 0) {
			while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			}
			if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			}
		}
		System.out.print(answer);
		sc.close();
	} 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 + 2]; h new int[n + 2] n + 2 n 2 int answer = 0; answer 0 for (int i = 1; i <= n; i++) {
			h[i] = sc.nextInt();
		} int i = 1; int i = 1; i 1 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 flag = 0; flag 0 int flag2 = 0; flag2 0 int hoge = 0; hoge 0 int i = 1; i 1 while (flag == 0) {
			while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			}
			if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			}
		} flag == 0 flag 0 {
			while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			}
			if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			}
		} while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			} h[i] != 0 && i <= n h[i] != 0 h[i] h i 0 i <= n i n {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			} hoge = h[i] hoge h[i] h i h[i]-- h[i] h i i++ i flag2++ flag2 if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			} i == n + 1 && flag2 == 0 i == n + 1 i n + 1 n 1 flag2 == 0 flag2 0 {
				flag++;
			} flag++ flag if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			} i == n + 1 i n + 1 n 1 {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} flag2 = 0 flag2 0 i = 1 i 1 if (hoge != 0) {
					answer++;
				} hoge != 0 hoge 0 {
					answer++;
				} answer++ answer hoge = 0 hoge 0 if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			} hoge != 0 hoge 0 {
				answer++;
				i++;
				hoge = 0;
			} answer++ answer i++ i hoge = 0 hoge 0 {
				i++;
				hoge = 0;
			} i++ i hoge = 0 hoge 0 System.out.print(answer) System.out.print System.out System System.out answer sc.close() sc.close sc String args[] args
import 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 + 2];
		int answer = 0;
		for (int i = 1; i <= n; i++) {
			h[i] = sc.nextInt();
		}
		int flag = 0;
		int flag2 = 0;

		int hoge = 0;
		int i = 1;
		while (flag == 0) {
			while (h[i] != 0 && i <= n) {
				hoge = h[i];
				h[i]--;
				i++;
				flag2++;
			}
			if (i == n + 1 && flag2 == 0) {
				flag++;
			} else if (i == n + 1) {
				flag2 = 0;
				i = 1;
				if (hoge != 0) {
					answer++;
				}
				hoge = 0;
			} else if (hoge != 0) {
				answer++;
				i++;
				hoge = 0;
			} else {
				i++;
				hoge = 0;
			}
		}
		System.out.print(answer);
		sc.close();
	}
}
