import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main{
  static int get_maxindex(int[] array){
    int max =0;
    int max_i=0;
    int i=0;
    for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    }
    return max_i;
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] flowers = new int[n];
    for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    }
    int max_index = get_maxindex(flowers);
    int count =0;
    while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    }
    System.out.println(count);


  }
} import java.util.Scanner; Scanner java.util import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util public class Main{
  static int get_maxindex(int[] array){
    int max =0;
    int max_i=0;
    int i=0;
    for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    }
    return max_i;
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] flowers = new int[n];
    for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    }
    int max_index = get_maxindex(flowers);
    int count =0;
    while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    }
    System.out.println(count);


  }
} Main static int get_maxindex(int[] array){
    int max =0;
    int max_i=0;
    int i=0;
    for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    }
    return max_i;
  } get_maxindex {
    int max =0;
    int max_i=0;
    int i=0;
    for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    }
    return max_i;
  } int max =0; max 0 int max_i=0; max_i 0 int i=0; i 0 for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    } int a array {
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    } {
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    } if(a>max){
        max = a;
        max_i = i;
      } a>max a max {
        max = a;
        max_i = i;
      } max = a max a max_i = i max_i i i+=1 i 1 return max_i; max_i int[] array array public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] flowers = new int[n];
    for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    }
    int max_index = get_maxindex(flowers);
    int count =0;
    while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    }
    System.out.println(count);


  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] flowers = new int[n];
    for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    }
    int max_index = get_maxindex(flowers);
    int count =0;
    while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    }
    System.out.println(count);


  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] flowers = new int[n]; flowers new int[n] n for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      flowers[i] = sc.nextInt();
    } {
      flowers[i] = sc.nextInt();
    } flowers[i] = sc.nextInt() flowers[i] flowers i sc.nextInt() sc.nextInt sc int max_index = get_maxindex(flowers); max_index get_maxindex(flowers) get_maxindex flowers int count =0; count 0 while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    } flowers[max_index]!=0 flowers[max_index] flowers max_index 0 {
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    } int j=0; j 0 while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     } j<n j n {
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     } if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      } flowers[j]==0 flowers[j] flowers j 0 {j++;} j++ j {
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      } count+=1 count 1 while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        } j<n&&flowers[j]!=0 j<n j n flowers[j]!=0 flowers[j] flowers j 0 {
          flowers[j] = flowers[j] -1;
          j+=1;
        } flowers[j] = flowers[j] -1 flowers[j] flowers j flowers[j] -1 flowers[j] flowers j 1 j+=1 j 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{
  static int get_maxindex(int[] array){
    int max =0;
    int max_i=0;
    int i=0;
    for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    }
    return max_i;
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] flowers = new int[n];
    for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    }
    int max_index = get_maxindex(flowers);
    int count =0;
    while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    }
    System.out.println(count);


  }
} public class Main{
  static int get_maxindex(int[] array){
    int max =0;
    int max_i=0;
    int i=0;
    for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    }
    return max_i;
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] flowers = new int[n];
    for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    }
    int max_index = get_maxindex(flowers);
    int count =0;
    while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    }
    System.out.println(count);


  }
} Main
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main{
  static int get_maxindex(int[] array){
    int max =0;
    int max_i=0;
    int i=0;
    for(int a : array){
      if(a>max){
        max = a;
        max_i = i;
      }
      i+=1;
    }
    return max_i;
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] flowers = new int[n];
    for(int i=0; i<n; i++){
      flowers[i] = sc.nextInt();
    }
    int max_index = get_maxindex(flowers);
    int count =0;
    while(flowers[max_index]!=0){
    int j=0;
     while(j<n){
      if(flowers[j]==0){j++;}
      else{
        count+=1;
        while(j<n&&flowers[j]!=0){
          flowers[j] = flowers[j] -1;
          j+=1;
        }
      }
     }
    }
    System.out.println(count);


  }
}