import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	}
}
//end import java.util.*; util.* java public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	}
} Main public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	} main {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n =Integer.parseInt(scan.next()); n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int[] h=new int [n]; h new int [n] n int max=0; max 0 for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		} int i=0; int i=0; i 0 i<n i n ++i ++i i {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		} {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		} h[i]=Integer.parseInt(scan.next()) h[i] h i Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan max=Math.max(max, h[i]) max Math.max(max, h[i]) Math.max Math max h[i] h i int count=0; count 0 boolean last=false; last false while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		} max>0 max 0 {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		} --max max count++ count last=false last false for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			} int i=0; int i=0; i 0 i<n i n ++i ++i i {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			} {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			} if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				} h[i]>0 h[i] h i 0 {	
					last=true;
					--h[i];
				} last=true last true --h[i] h[i] h i if (i+1<n&&h[i+1]>0&&last) {
					++count;
				} i+1<n&&h[i+1]>0&&last i+1<n&&h[i+1]>0&&last i+1<n i+1 i 1 n h[i+1]>0 h[i+1] h i+1 i 1 0 last {
					++count;
				} ++count count System.out.print(count) System.out.print System.out System System.out count String[] args args public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	}
} public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	}
}
//end
