import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int k[] = new int[N];
		Boolean allZero = false;
		int count = 0;

		for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		}

		while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
	}
}; import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int k[] = new int[N];
		Boolean allZero = false;
		int count = 0;

		for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		}

		while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int k[] = new int[N];
		Boolean allZero = false;
		int count = 0;

		for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		}

		while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int k[] = new int[N];
		Boolean allZero = false;
		int count = 0;

		for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		}

		while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int k[] = new int[N]; k new int[N] N Boolean allZero = false; allZero false int count = 0; count 0 for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			k[i] = sc.nextInt();
		} {
			k[i] = sc.nextInt();
		} k[i] = sc.nextInt() k[i] k i sc.nextInt() sc.nextInt sc while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		} !allZero allZero {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		} allZero = true allZero true int now = 0; now 0 Boolean isZero = true; isZero true while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			} now < N now N {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			} if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				} k[now] > 0 k[now] k now 0 {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} k[now] -= 1 k[now] k now 1 isZero = false isZero false allZero = false allZero false if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				} k[now] <= 0 && isZero k[now] <= 0 k[now] k now 0 isZero {
				} {
					count++;
					isZero = true;
				} count++ count isZero = true isZero true now++ now if (!isZero) {
				count++;
			} !isZero isZero {
				count++;
			} count++ count sc.close() sc.close sc System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int k[] = new int[N];
		Boolean allZero = false;
		int count = 0;

		for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		}

		while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int k[] = new int[N];
		Boolean allZero = false;
		int count = 0;

		for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		}

		while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
	}
} Main
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int k[] = new int[N];
		Boolean allZero = false;
		int count = 0;

		for (int i = 0; i < N; i++) {
			k[i] = sc.nextInt();
		}

		while (!allZero) {
			allZero = true;
			int now = 0;
			Boolean isZero = true;
			while (now < N) {
				if (k[now] > 0) {
					k[now] -= 1;
					isZero = false;
					allZero = false;
				} else if (k[now] <= 0 && isZero) {
				} else {
					count++;
					isZero = true;
				}
				now++;
			}
			if (!isZero) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
	}
};