import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	}
} Main public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	} main {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = Integer.parseInt(scanner.next()); N Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int[] H = new int[N]; H new int[N] N for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
	    	H[i] = Integer.parseInt(scanner.next());
	    } {
	    	H[i] = Integer.parseInt(scanner.next());
	    } H[i] = Integer.parseInt(scanner.next()) H[i] H i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int c=0; c 0 while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    } true {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    } boolean flg= false; flg false for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    } {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    } if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	} H[i] != 0 H[i] H i 0 {
		    		H[i]--;
		    		flg=true;
		    	} H[i]-- H[i] H i flg=true flg true if(flg) {
		    		break;
		    	} flg {
		    		break;
		    	} break; if (!flg) {
	    		break;
	    	} !flg flg {
	    		break;
	    	} break; c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	}
} public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	}
}