import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int MAX = 0;
		for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		}
		int ans = 0;
		for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		}
		System.out.println(ans);
		sc.close();
	}
	
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int MAX = 0;
		for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		}
		int ans = 0;
		for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		}
		System.out.println(ans);
		sc.close();
	}
	
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int MAX = 0;
		for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		}
		int ans = 0;
		for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		}
		System.out.println(ans);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int MAX = 0;
		for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		}
		int ans = 0;
		for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		}
		System.out.println(ans);
		sc.close();
	} 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 int MAX = 0; MAX 0 for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		} {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		} h[i]  = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc MAX = Math.max(MAX, h[i]) MAX Math.max(MAX, h[i]) Math.max Math MAX h[i] h i int ans = 0; ans 0 for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		} int i = 0; int i = 0; i 0 i < MAX i MAX i++ i++ i {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		} {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		} int tmp = 1; tmp 1 int nzero = 0; nzero 0 if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			} h[0] == 0 h[0] h 0 0 {
				while(h[nzero] == 0) {
					nzero ++;
				}
			} while(h[nzero] == 0) {
					nzero ++;
				} h[nzero] == 0 h[nzero] h nzero 0 {
					nzero ++;
				} nzero ++ nzero for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			} int j = nzero; int j = nzero; j nzero j < n-1 j n-1 n 1 j++ j++ j {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			} {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			} if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				} h[j] * h[j+1] == 0 && h[j+1] == 0 h[j] * h[j+1] == 0 h[j] * h[j+1] h[j] h j h[j+1] h j+1 j 1 0 h[j+1] == 0 h[j+1] h j+1 j 1 0 {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				} if(h[j] + h[j+1] != 0) {
						tmp ++;
					} h[j] + h[j+1] != 0 h[j] + h[j+1] h[j] h j h[j+1] h j+1 j 1 0 {
						tmp ++;
					} tmp ++ tmp if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			} h[n-1] == 0 && h[nzero] != 0 h[n-1] == 0 h[n-1] h n-1 n 1 0 h[nzero] != 0 h[nzero] h nzero 0 {
				tmp --;
			} tmp -- tmp for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
				if(h[j] != 0) {
					h[j] --;
				}
			} {
				if(h[j] != 0) {
					h[j] --;
				}
			} if(h[j] != 0) {
					h[j] --;
				} h[j] != 0 h[j] h j 0 {
					h[j] --;
				} h[j] -- h[j] h j ans += tmp ans tmp System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int MAX = 0;
		for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		}
		int ans = 0;
		for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		}
		System.out.println(ans);
		sc.close();
	}
	
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int MAX = 0;
		for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		}
		int ans = 0;
		for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		}
		System.out.println(ans);
		sc.close();
	}
	
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int MAX = 0;
		for(int i = 0; i < n; i++) {
			h[i]  = sc.nextInt();
			MAX = Math.max(MAX, h[i]);
		}
		int ans = 0;
		for(int i = 0; i < MAX; i++) {
			int tmp = 1;
			int nzero = 0;
			if(h[0] == 0) {
				while(h[nzero] == 0) {
					nzero ++;
				}
			}
			for(int j = nzero; j < n-1; j++) {
				if(h[j] * h[j+1] == 0 && h[j+1] == 0) {
					if(h[j] + h[j+1] != 0) {
						tmp ++;
					}
					
				}
			}
			if(h[n-1] == 0 && h[nzero] != 0) {
				tmp --;
			}
			for(int j = 0; j < n; j++) {
				if(h[j] != 0) {
					h[j] --;
				}
			}
			
			ans += tmp;
			//System.out.println(ans);
		}
		System.out.println(ans);
		sc.close();
	}
	
}

