import java.util.Scanner;

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 count =0;
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    
    int a =0; int b=0;
    L:while (a<= N-1 && b<= N-1) {
      if (h[a] ==0) {
        a++;
        continue;
      }
      //aを決定
      b = a;
      while (b <= N-1) {
        if (h[b] !=0 && b != N -1) {
          b++;
          continue;
        } else {
          for (int i =a; i<=b; i++) {
            h[i]--;
            if (h[i] <0) {
              h[i] =0;
            }
          }
        }
        count++;
        continue L;
      }
    }
    System.out.println(count);
  }
} import java.util.Scanner; Scanner 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 count =0;
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    
    int a =0; int b=0;
    L:while (a<= N-1 && b<= N-1) {
      if (h[a] ==0) {
        a++;
        continue;
      }
      //aを決定
      b = a;
      while (b <= N-1) {
        if (h[b] !=0 && b != N -1) {
          b++;
          continue;
        } else {
          for (int i =a; i<=b; i++) {
            h[i]--;
            if (h[i] <0) {
              h[i] =0;
            }
          }
        }
        count++;
        continue L;
      }
    }
    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];
    int count =0;
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    
    int a =0; int b=0;
    L:while (a<= N-1 && b<= N-1) {
      if (h[a] ==0) {
        a++;
        continue;
      }
      //aを決定
      b = a;
      while (b <= N-1) {
        if (h[b] !=0 && b != N -1) {
          b++;
          continue;
        } else {
          for (int i =a; i<=b; i++) {
            h[i]--;
            if (h[i] <0) {
              h[i] =0;
            }
          }
        }
        count++;
        continue L;
      }
    }
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] h = new int[N];
    int count =0;
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    
    int a =0; int b=0;
    L:while (a<= N-1 && b<= N-1) {
      if (h[a] ==0) {
        a++;
        continue;
      }
      //aを決定
      b = a;
      while (b <= N-1) {
        if (h[b] !=0 && b != N -1) {
          b++;
          continue;
        } else {
          for (int i =a; i<=b; i++) {
            h[i]--;
            if (h[i] <0) {
              h[i] =0;
            }
          }
        }
        count++;
        continue L;
      }
    }
    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 int count =0; count 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 int a =0; a 0 int b=0; b 0 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];
    int count =0;
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    
    int a =0; int b=0;
    L:while (a<= N-1 && b<= N-1) {
      if (h[a] ==0) {
        a++;
        continue;
      }
      //aを決定
      b = a;
      while (b <= N-1) {
        if (h[b] !=0 && b != N -1) {
          b++;
          continue;
        } else {
          for (int i =a; i<=b; i++) {
            h[i]--;
            if (h[i] <0) {
              h[i] =0;
            }
          }
        }
        count++;
        continue L;
      }
    }
    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];
    int count =0;
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    
    int a =0; int b=0;
    L:while (a<= N-1 && b<= N-1) {
      if (h[a] ==0) {
        a++;
        continue;
      }
      //aを決定
      b = a;
      while (b <= N-1) {
        if (h[b] !=0 && b != N -1) {
          b++;
          continue;
        } else {
          for (int i =a; i<=b; i++) {
            h[i]--;
            if (h[i] <0) {
              h[i] =0;
            }
          }
        }
        count++;
        continue L;
      }
    }
    System.out.println(count);
  }
} Main
import java.util.Scanner;

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 count =0;
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    
    int a =0; int b=0;
    L:while (a<= N-1 && b<= N-1) {
      if (h[a] ==0) {
        a++;
        continue;
      }
      //aを決定
      b = a;
      while (b <= N-1) {
        if (h[b] !=0 && b != N -1) {
          b++;
          continue;
        } else {
          for (int i =a; i<=b; i++) {
            h[i]--;
            if (h[i] <0) {
              h[i] =0;
            }
          }
        }
        count++;
        continue L;
      }
    }
    System.out.println(count);
  }
}