import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] h = new int[N];
		for (int i=0;i<N;i++) {
			h[i]=Integer.parseInt(sc.next());
		}

		int cnt=0;
		loop:while (true) {
			int left=0;
			for (int i=0;i<N;i++) {
				if (h[i]!=0) {
					left=i;
					break;
				}
				if (i==N-1) {
					break loop;
				}
			}
			for (int i=left;i<N;i++) {
				if (h[i]>0) {
					h[i]--;
					if (i==N-1) {
						cnt++;
					}
				} else if (h[i]==0 || i==N-1) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] h = new int[N];
		for (int i=0;i<N;i++) {
			h[i]=Integer.parseInt(sc.next());
		}

		int cnt=0;
		loop:while (true) {
			int left=0;
			for (int i=0;i<N;i++) {
				if (h[i]!=0) {
					left=i;
					break;
				}
				if (i==N-1) {
					break loop;
				}
			}
			for (int i=left;i<N;i++) {
				if (h[i]>0) {
					h[i]--;
					if (i==N-1) {
						cnt++;
					}
				} else if (h[i]==0 || i==N-1) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] h = new int[N];
		for (int i=0;i<N;i++) {
			h[i]=Integer.parseInt(sc.next());
		}

		int cnt=0;
		loop:while (true) {
			int left=0;
			for (int i=0;i<N;i++) {
				if (h[i]!=0) {
					left=i;
					break;
				}
				if (i==N-1) {
					break loop;
				}
			}
			for (int i=left;i<N;i++) {
				if (h[i]>0) {
					h[i]--;
					if (i==N-1) {
						cnt++;
					}
				} else if (h[i]==0 || i==N-1) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] h = new int[N];
		for (int i=0;i<N;i++) {
			h[i]=Integer.parseInt(sc.next());
		}

		int cnt=0;
		loop:while (true) {
			int left=0;
			for (int i=0;i<N;i++) {
				if (h[i]!=0) {
					left=i;
					break;
				}
				if (i==N-1) {
					break loop;
				}
			}
			for (int i=left;i<N;i++) {
				if (h[i]>0) {
					h[i]--;
					if (i==N-1) {
						cnt++;
					}
				} else if (h[i]==0 || i==N-1) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] h = new int[N]; h new int[N] N for (int i=0;i<N;i++) {
			h[i]=Integer.parseInt(sc.next());
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			h[i]=Integer.parseInt(sc.next());
		} {
			h[i]=Integer.parseInt(sc.next());
		} h[i]=Integer.parseInt(sc.next()) h[i] h i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int cnt=0; cnt 0 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] h = new int[N];
		for (int i=0;i<N;i++) {
			h[i]=Integer.parseInt(sc.next());
		}

		int cnt=0;
		loop:while (true) {
			int left=0;
			for (int i=0;i<N;i++) {
				if (h[i]!=0) {
					left=i;
					break;
				}
				if (i==N-1) {
					break loop;
				}
			}
			for (int i=left;i<N;i++) {
				if (h[i]>0) {
					h[i]--;
					if (i==N-1) {
						cnt++;
					}
				} else if (h[i]==0 || i==N-1) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}
}