import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int h[] = new int[N];
	static int ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	}

	public static void solv(int st) {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int h[] = new int[N];
	static int ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	}

	public static void solv(int st) {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc static int h[] = new int[N]; h new int[N] N static int ans = 0; ans 0 public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	} main {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	} 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 while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		} true {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		} for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			} {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			} if(h[i] > 0) {
					solv(i);
					break;
				} h[i] > 0 h[i] h i 0 {
					solv(i);
					break;
				} solv(i) solv i break; if(i == N - 1) {
					System.out.println(ans);
					return;
				} i == N - 1 i N - 1 N 1 {
					System.out.println(ans);
					return;
				} System.out.println(ans) System.out.println System.out System System.out ans return; String[] args args public static void solv(int st) {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	} solv {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	} ans++ ans for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		} int i = st; int i = st; i st i < N i N i++ i++ i {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		} {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		} if(h[i] == 0)
				return;
			else
				h[i]--; h[i] == 0 h[i] h i 0 return; h[i]-- h[i] h i int st st public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int h[] = new int[N];
	static int ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	}

	public static void solv(int st) {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	}
} public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int h[] = new int[N];
	static int ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	}

	public static void solv(int st) {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	}
} Main
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int h[] = new int[N];
	static int ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	}

	public static void solv(int st) {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	}
}