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