import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int next(int[] h, int idx) {
		for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		}
		return -1;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int ans = 0;
		int idx = 0;
		while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		}

		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int next(int[] h, int idx) {
		for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		}
		return -1;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int ans = 0;
		int idx = 0;
		while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		}

		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

} Main InputStream in = System.in; in System.in System System.in PrintStream out = System.out; out System.out System System.out int next(int[] h, int idx) {
		for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		}
		return -1;
	} next {
		for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		}
		return -1;
	} for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		} int i = idx; int i = idx; i idx i < h.length i h.length h h.length i++ i++ i {
			if (h[i] != 0) {
				return i;
			}
		} {
			if (h[i] != 0) {
				return i;
			}
		} if (h[i] != 0) {
				return i;
			} h[i] != 0 h[i] h i 0 {
				return i;
			} return i; i return -1; -1 1 int[] h h int idx idx public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int ans = 0;
		int idx = 0;
		while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		}

		out.println(ans);

		sc.close();

	} _main {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int ans = 0;
		int idx = 0;
		while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		}

		out.println(ans);

		sc.close();

	} Scanner sc = new Scanner(in); sc new Scanner(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 int idx = 0; idx 0 while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		} true {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		} idx = next(h, idx) idx next(h, idx) next h idx if (idx == -1) {
				break;
			} idx == -1 idx -1 1 {
				break;
			} break; while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			} h[idx] > 0 h[idx] h idx 0 {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			} ans++ ans for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				} int i = idx; int i = idx; i idx i < n && h[i] > 0 i < n i n h[i] > 0 h[i] h i 0 i++ i++ i {
					h[i]--;
				} {
					h[i]--;
				} h[i]-- h[i] h i out.println(ans) out.println out ans sc.close() sc.close sc String[] args args public static void main(String[] args) {
		new Main()._main(args);
	} main {
		new Main()._main(args);
	} new Main()._main(args) new Main()._main new Main() args String[] args args public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int next(int[] h, int idx) {
		for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		}
		return -1;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int ans = 0;
		int idx = 0;
		while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		}

		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

} public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int next(int[] h, int idx) {
		for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		}
		return -1;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int ans = 0;
		int idx = 0;
		while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		}

		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int next(int[] h, int idx) {
		for (int i = idx; i < h.length; i++) {
			if (h[i] != 0) {
				return i;
			}
		}
		return -1;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int ans = 0;
		int idx = 0;
		while (true) {
			idx = next(h, idx);
			if (idx == -1) {
				break;
			}

			while (h[idx] > 0) {
				ans++;
				for (int i = idx; i < n && h[i] > 0; i++) {
					h[i]--;
				}
			}
		}

		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}
