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];
		int maxH = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		
		int ans = 0;
		for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						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];
		int maxH = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		
		int ans = 0;
		for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						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];
		int maxH = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		
		int ans = 0;
		for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			}
		}
		
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int maxH = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		
		int ans = 0;
		for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						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 int maxH = 0; maxH 0 for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		} {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc maxH = Math.max(maxH, h[i]) maxH Math.max(maxH, h[i]) Math.max Math maxH h[i] h i int ans = 0; ans 0 for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			}
		} int i = 0; int i = 0; i 0 i < maxH i maxH i++ i++ i {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			}
		} {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			}
		} for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			} {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			} if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				} h[j] > 0 h[j] h j 0 {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				} h[j]-- h[j] h j if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					} j + 1 == n || h[j + 1] == 0 j + 1 == n j + 1 j 1 n h[j + 1] == 0 h[j + 1] h j + 1 j 1 0 {
						ans++;
					} 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];
		int maxH = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		
		int ans = 0;
		for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						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];
		int maxH = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		
		int ans = 0;
		for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						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];
		int maxH = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		
		int ans = 0;
		for (int i = 0; i < maxH; i++) {
			for (int j = 0; j < n; j++) {
				if (h[j] > 0) {
					h[j]--;
					if (j + 1 == n || h[j + 1] == 0) {
						ans++;
					}
				}
			}
		}
		
		System.out.println(ans);
	}
}
