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];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    int tmp = 0;
    int count = 0;
    do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count);
    System.out.println(count);
  }
} 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];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    int tmp = 0;
    int count = 0;
    do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count);
    System.out.println(count);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int h[] = new int[N];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    int tmp = 0;
    int count = 0;
    do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count);
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int h[] = new int[N];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    int tmp = 0;
    int count = 0;
    do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count);
    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 h[] = new int[N]; h new int[N] N 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 int tmp = 0; tmp 0 int count = 0; count 0 do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count); tmp != count tmp count {
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    } tmp = count tmp count int min = 100; min 100 int index = 0; index 0 int lastValue = 0; lastValue 0 for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      } {
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      } if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        } h[i] == 0 h[i] h i 0 {
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        } if(lastValue == 0){
            index = i + 1;
            continue;
          } lastValue == 0 lastValue 0 {
            index = i + 1;
            continue;
          } index = i + 1 index i + 1 i 1 continue; for(int j = index; j < i; j++){
            h[j] -= min;
          } int j = index; int j = index; j index j < i j i j++ j++ j {
            h[j] -= min;
          } {
            h[j] -= min;
          } h[j] -= min h[j] h j min count += min count min min = 100 min 100 index = i + 1 index i + 1 i 1 lastValue = 0 lastValue 0 if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        } i == N-1 i N-1 N 1 {
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        } min = (min < h[i]) ? min : h[i] min (min < h[i]) ? min : h[i] (min < h[i]) min h[i] h i min h[i] h i for(int j = index; j <= i; j++){
            h[j] -= min;
          } int j = index; int j = index; j index j <= i j i j++ j++ j {
            h[j] -= min;
          } {
            h[j] -= min;
          } h[j] -= min h[j] h j min count += min count min min = 100 min 100 index = i + 1 index i + 1 i 1 min = (min < h[i]) ? min : h[i] min (min < h[i]) ? min : h[i] (min < h[i]) min h[i] h i min h[i] h i lastValue = h[i] lastValue h[i] h i System.out.println(count) System.out.println System.out System System.out count 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];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    int tmp = 0;
    int count = 0;
    do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count);
    System.out.println(count);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int h[] = new int[N];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    int tmp = 0;
    int count = 0;
    do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count);
    System.out.println(count);
  }
} 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];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    int tmp = 0;
    int count = 0;
    do{
      tmp = count;
      int min = 100;
      int index = 0;
      int lastValue = 0;
      for(int i = 0; i < N; i++){
        if(h[i] == 0){
          if(lastValue == 0){
            index = i + 1;
            continue;
          }
          for(int j = index; j < i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
          lastValue = 0;
        }else if(i == N-1){
          min = (min < h[i]) ? min : h[i];
          for(int j = index; j <= i; j++){
            h[j] -= min;
          }
          count += min;
          min = 100;
          index = i + 1;
        }
        min = (min < h[i]) ? min : h[i];
        lastValue = h[i];
      }
    }while(tmp != count);
    System.out.println(count);
  }
}