import java.util.*;
class Main {
  public static void main (String[] args) throws Exception {
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int [] f = new int [n];
    
    int ans=0;
    
    for(int i=0; i<n; i++){
      f[i]=sc.nextInt();
     }
     
     boolean flag = false;
     int count =0;
     int d=0;
      
     while(count<n){
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       }
       
      System.out.println(ans);

  }
  
} import java.util.*; util.* java class Main {
  public static void main (String[] args) throws Exception {
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int [] f = new int [n];
    
    int ans=0;
    
    for(int i=0; i<n; i++){
      f[i]=sc.nextInt();
     }
     
     boolean flag = false;
     int count =0;
     int d=0;
      
     while(count<n){
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       }
       
      System.out.println(ans);

  }
  
} Main public static void main (String[] args) throws Exception {
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int [] f = new int [n];
    
    int ans=0;
    
    for(int i=0; i<n; i++){
      f[i]=sc.nextInt();
     }
     
     boolean flag = false;
     int count =0;
     int d=0;
      
     while(count<n){
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       }
       
      System.out.println(ans);

  } main {
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int [] f = new int [n];
    
    int ans=0;
    
    for(int i=0; i<n; i++){
      f[i]=sc.nextInt();
     }
     
     boolean flag = false;
     int count =0;
     int d=0;
      
     while(count<n){
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       }
       
      System.out.println(ans);

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int [] f = new int [n]; f new int [n] n int ans=0; ans 0 for(int i=0; i<n; i++){
      f[i]=sc.nextInt();
     } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      f[i]=sc.nextInt();
     } {
      f[i]=sc.nextInt();
     } f[i]=sc.nextInt() f[i] f i sc.nextInt() sc.nextInt sc boolean flag = false; flag false int count =0; count 0 int d=0; d 0 while(count<n){
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       } count<n count n {
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       } if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          } d==n d n {
          d=0;
          if(flag==true)ans++;
          flag=false;
          } d=0 d 0 if(flag==true)ans++; flag==true flag true ans++ ans flag=false flag false if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          } f[d]!=0 f[d] f d 0 {
         count=0;
         flag = true;
         f[d]--;
         } count=0 count 0 flag = true flag true f[d]-- f[d] f d {
           if(flag==true)ans++;
           flag=false;
           count++;
          } if(flag==true)ans++; flag==true flag true ans++ ans flag=false flag false count++ count d++ d System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;
class Main {
  public static void main (String[] args) throws Exception {
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int [] f = new int [n];
    
    int ans=0;
    
    for(int i=0; i<n; i++){
      f[i]=sc.nextInt();
     }
     
     boolean flag = false;
     int count =0;
     int d=0;
      
     while(count<n){
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       }
       
      System.out.println(ans);

  }
  
}