import java.util.Scanner;

public 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;

		for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		}

		boolean start = false;
		boolean zero = false;
		boolean none = true;
		for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		}

		if (none == false)
			ans++;

		System.out.println(ans);

	}
} 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 h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int ans = 0;

		for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		}

		boolean start = false;
		boolean zero = false;
		boolean none = true;
		for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		}

		if (none == false)
			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;

		for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		}

		boolean start = false;
		boolean zero = false;
		boolean none = true;
		for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		}

		if (none == false)
			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;

		for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		}

		boolean start = false;
		boolean zero = false;
		boolean none = true;
		for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		}

		if (none == false)
			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 for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		} {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		} while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			} h[i] > 1 h[i] h i 1 {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			} ans++ ans h[i]-- h[i] h i for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				} int i2 = i + 1; int i2 = i + 1; i2 i + 1 i 1 i2 < h.length i2 h.length h h.length i2++ i2++ i2 {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				} {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				} if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					} h[i2] > 1 h[i2] h i2 1 {
						h[i2]--;
					} h[i2]-- h[i2] h i2 {
						break;
					} break; boolean start = false; start false boolean zero = false; zero false boolean none = true; none true for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		} {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		} if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			} h[i] != 0 h[i] h i 0 {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			} none = false none false start = true start true if (zero == true) {
					ans++;
					zero = false;
				} zero == true zero true {
					ans++;
					zero = false;
				} ans++ ans zero = false zero false if (h[i] == 0 && none == false) {
				zero = true;
			} h[i] == 0 && none == false h[i] == 0 h[i] h i 0 none == false none false {
				zero = true;
			} zero = true zero true if (none == false)
			ans++; none == false none false ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public 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;

		for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		}

		boolean start = false;
		boolean zero = false;
		boolean none = true;
		for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		}

		if (none == false)
			ans++;

		System.out.println(ans);

	}
} public 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;

		for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		}

		boolean start = false;
		boolean zero = false;
		boolean none = true;
		for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		}

		if (none == false)
			ans++;

		System.out.println(ans);

	}
} 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 h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int ans = 0;

		for (int i = 0; i < n; i++) {
			while (h[i] > 1) {
				ans++;
				h[i]--;
				for (int i2 = i + 1; i2 < h.length; i2++) {
					if (h[i2] > 1) {
						h[i2]--;
					} else {
						break;
					}
				}
			}
		}

		boolean start = false;
		boolean zero = false;
		boolean none = true;
		for (int i = 0; i < n; i++) {
			if (h[i] != 0) {
				none = false;
				start = true;
				if (zero == true) {
					ans++;
					zero = false;
				}
			}
			if (h[i] == 0 && none == false) {
				zero = true;
			}
		}

		if (none == false)
			ans++;

		System.out.println(ans);

	}
}
