import 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];
	    int sum = 0;
	    int end = 0;
	    int w = 0;
	    for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    }
	    while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    }
	    System.out.println(sum);
	  }
} import java.util.*; util.* java public class Main {
	  public static void main(String[] args) {

	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int h[] = new int[n];
	    int sum = 0;
	    int end = 0;
	    int w = 0;
	    for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    }
	    while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    }
	    System.out.println(sum);
	  }
} Main public static void main(String[] args) {

	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int h[] = new int[n];
	    int sum = 0;
	    int end = 0;
	    int w = 0;
	    for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    }
	    while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    }
	    System.out.println(sum);
	  } main {

	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int h[] = new int[n];
	    int sum = 0;
	    int end = 0;
	    int w = 0;
	    for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    }
	    while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    }
	    System.out.println(sum);
	  } 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 sum = 0; sum 0 int end = 0; end 0 int w = 0; w 0 for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
	      h[i] = sc.nextInt();
	    } {
	      h[i] = sc.nextInt();
	    } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    } end <= n end n {
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    } end = 0 end 0 for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      } int i=0; int i=0; i 0 i<n i n i++ i++ i {
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      } {
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      } if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        } h[i] == 0 h[i] h i 0 {
	          end++;
	        } end++ end {
	          w = i;
	          break;
	        } w = i w i break; if(end >= n){
	        break;
	      } end >= n end n {
	        break;
	      } break; while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      } w < n w n {
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      } if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        } h[w] <= 0 h[w] h w 0 {
	          break;
	        } break; {
	          h[w]--;
	        } h[w]-- h[w] h w w++ w sum++ sum System.out.println(sum) System.out.println System.out System System.out sum 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];
	    int sum = 0;
	    int end = 0;
	    int w = 0;
	    for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    }
	    while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    }
	    System.out.println(sum);
	  }
} public class Main {
	  public static void main(String[] args) {

	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int h[] = new int[n];
	    int sum = 0;
	    int end = 0;
	    int w = 0;
	    for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    }
	    while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    }
	    System.out.println(sum);
	  }
} Main
import 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];
	    int sum = 0;
	    int end = 0;
	    int w = 0;
	    for(int i=0; i<n; i++) {
	      h[i] = sc.nextInt();
	    }
	    while(end <= n){
	      end = 0;
	  	  for(int i=0; i<n; i++){
	        if(h[i] == 0){
	          end++;
	        }else{
	          w = i;
	          break;
	        }
	      }
	      if(end >= n){
	        break;
	      }
	      while(w < n){
	        if(h[w] <= 0){
	          break;
	        }else{
	          h[w]--;
	        }
	        w++;
	      }
	      sum++;
	    }
	    System.out.println(sum);
	  }
}