import java.util.Scanner;


	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int[] h = new int[n+2];
			int maxh = 0;
			int zero1 = 0;
			int zero2 = n;
			int ret = 0;
			
			for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			}
			
			h[0] = 0;
			h[n+1] = 0;
			
			for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			}
			
			System.out.println(ret);
			
		}
		
		
		
	} import java.util.Scanner; Scanner 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+2];
			int maxh = 0;
			int zero1 = 0;
			int zero2 = n;
			int ret = 0;
			
			for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			}
			
			h[0] = 0;
			h[n+1] = 0;
			
			for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			}
			
			System.out.println(ret);
			
		}
		
		
		
	} Main public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int[] h = new int[n+2];
			int maxh = 0;
			int zero1 = 0;
			int zero2 = n;
			int ret = 0;
			
			for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			}
			
			h[0] = 0;
			h[n+1] = 0;
			
			for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			}
			
			System.out.println(ret);
			
		} main {

			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int[] h = new int[n+2];
			int maxh = 0;
			int zero1 = 0;
			int zero2 = n;
			int ret = 0;
			
			for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			}
			
			h[0] = 0;
			h[n+1] = 0;
			
			for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			}
			
			System.out.println(ret);
			
		} 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+2]; h new int[n+2] n+2 n 2 int maxh = 0; maxh 0 int zero1 = 0; zero1 0 int zero2 = n; zero2 n int ret = 0; ret 0 for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			} int i=1; int i=1; i 1 i<n+1 i n+1 n 1 i++ i++ i {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			} {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc maxh = Math.max(maxh, h[i]) maxh Math.max(maxh, h[i]) Math.max Math maxh h[i] h i h[0] = 0 h[0] h 0 0 h[n+1] = 0 h[n+1] h n+1 n 1 0 for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			} int i=1; int i=1; i 1 i<=maxh i maxh i++ i++ i {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			} {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			} zero1 = 0 zero1 0 zero2 = n zero2 n for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				} int j=0; int j=0; j 0 j<n+2 j n+2 n 2 j++ j++ j {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				} {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				} if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					} h[j]==0 h[j] h j 0 {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					} zero2 = j zero2 j if(zero2-zero1>1) {
							ret++;
						} zero2-zero1>1 zero2-zero1 zero2 zero1 1 {
							ret++;
						} ret++ ret zero1=zero2 zero1 zero2 for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				} int k=0; int k=0; k 0 k<n+2 k n+2 n 2 k++ k++ k {
					if(h[k]>0) {
						h[k]--;
					}
				} {
					if(h[k]>0) {
						h[k]--;
					}
				} if(h[k]>0) {
						h[k]--;
					} h[k]>0 h[k] h k 0 {
						h[k]--;
					} h[k]-- h[k] h k System.out.println(ret) System.out.println System.out System System.out ret 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+2];
			int maxh = 0;
			int zero1 = 0;
			int zero2 = n;
			int ret = 0;
			
			for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			}
			
			h[0] = 0;
			h[n+1] = 0;
			
			for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			}
			
			System.out.println(ret);
			
		}
		
		
		
	} public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int[] h = new int[n+2];
			int maxh = 0;
			int zero1 = 0;
			int zero2 = n;
			int ret = 0;
			
			for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			}
			
			h[0] = 0;
			h[n+1] = 0;
			
			for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			}
			
			System.out.println(ret);
			
		}
		
		
		
	} Main
import java.util.Scanner;


	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int[] h = new int[n+2];
			int maxh = 0;
			int zero1 = 0;
			int zero2 = n;
			int ret = 0;
			
			for(int i=1;i<n+1;i++) {
				h[i] = sc.nextInt();
				maxh = Math.max(maxh, h[i]);
			}
			
			h[0] = 0;
			h[n+1] = 0;
			
			for(int i=1;i<=maxh;i++) {
				zero1 = 0;
				zero2 = n;
				for(int j=0;j<n+2;j++) {
					if(h[j]==0) {
						zero2 = j;
						
						if(zero2-zero1>1) {
							ret++;
						}
						
						zero1=zero2;
					}
				
				}
				for(int k=0;k<n+2;k++) {
					if(h[k]>0) {
						h[k]--;
					}
				}
				
			}
			
			System.out.println(ret);
			
		}
		
		
		
	}
