import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		boolean check = true;
		int yono = 0;
		while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		}
		ou.print(yono + "\n");
		ou.flush();
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		boolean check = true;
		int yono = 0;
		while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		}
		ou.print(yono + "\n");
		ou.flush();
    }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		boolean check = true;
		int yono = 0;
		while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		}
		ou.print(yono + "\n");
		ou.flush();
    } main {
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		boolean check = true;
		int yono = 0;
		while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		}
		ou.print(yono + "\n");
		ou.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter ou = new PrintWriter(System.out); ou new PrintWriter(System.out) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[n]; a new int[n] n for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()); int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i a[i] = Integer.parseInt(sc.next()); a[i] = Integer.parseInt(sc.next()) a[i] a i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc boolean check = true; check true int yono = 0; yono 0 while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		} check {
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		} int cou = 0; cou 0 for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			} int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			} {
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			} if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				} a[i] != 0 a[i] a i 0 {
					cou++;
					a[i]--;
				} cou++ cou a[i]-- a[i] a i {
					if(cou != 0) yono++;
					cou = 0;
				} if(cou != 0) yono++; cou != 0 cou 0 yono++ yono cou = 0 cou 0 if(cou != 0) yono++; cou != 0 cou 0 yono++ yono boolean ch = true; ch true for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			} int i = 0 ; int i = 0 ; i 0 i < n && ch i < n i n ch i++ i++ i {
				if(a[i] != 0) ch = false;
			} {
				if(a[i] != 0) ch = false;
			} if(a[i] != 0) ch = false; a[i] != 0 a[i] a i 0 ch = false ch false if(ch) check = false; ch check = false check false ou.print(yono + "\n") ou.print ou yono + "\n" yono "\n" ou.flush() ou.flush ou String[] args args public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		boolean check = true;
		int yono = 0;
		while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		}
		ou.print(yono + "\n");
		ou.flush();
    }
} public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		boolean check = true;
		int yono = 0;
		while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		}
		ou.print(yono + "\n");
		ou.flush();
    }
} Main
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		boolean check = true;
		int yono = 0;
		while(check){
			int cou = 0;
			for(int i = 0 ; i < n ; i++){
				if(a[i] != 0){
					cou++;
					a[i]--;
				}else{
					if(cou != 0) yono++;
					cou = 0;
				}
			}
			if(cou != 0) yono++;
			boolean ch = true;
			for(int i = 0 ; i < n && ch ; i++){
				if(a[i] != 0) ch = false;
			}
			if(ch) check = false;
		}
		ou.print(yono + "\n");
		ou.flush();
    }
}