import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] l = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = scanner.nextInt();
    }
    scanner.close();
    int max = 0;
    for (int i = 0; i < n; i++) {
      if (max < l[i]) {
        max = l[i];
      }
    }
    if (n == 1) {
      System.out.println(max);
      return;
    }
    int count = 0;
    for (int i = max; i > 0; i--) {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    }
    System.out.println(count);

  }

} import java.util.Scanner; Scanner java.util class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] l = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = scanner.nextInt();
    }
    scanner.close();
    int max = 0;
    for (int i = 0; i < n; i++) {
      if (max < l[i]) {
        max = l[i];
      }
    }
    if (n == 1) {
      System.out.println(max);
      return;
    }
    int count = 0;
    for (int i = max; i > 0; i--) {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    }
    System.out.println(count);

  }

} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] l = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = scanner.nextInt();
    }
    scanner.close();
    int max = 0;
    for (int i = 0; i < n; i++) {
      if (max < l[i]) {
        max = l[i];
      }
    }
    if (n == 1) {
      System.out.println(max);
      return;
    }
    int count = 0;
    for (int i = max; i > 0; i--) {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    }
    System.out.println(count);

  } main {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] l = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = scanner.nextInt();
    }
    scanner.close();
    int max = 0;
    for (int i = 0; i < n; i++) {
      if (max < l[i]) {
        max = l[i];
      }
    }
    if (n == 1) {
      System.out.println(max);
      return;
    }
    int count = 0;
    for (int i = max; i > 0; i--) {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    }
    System.out.println(count);

  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] l = new int[n]; l new int[n] n for (int i = 0; i < n; i++) {
      l[i] = scanner.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      l[i] = scanner.nextInt();
    } {
      l[i] = scanner.nextInt();
    } l[i] = scanner.nextInt() l[i] l i scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int max = 0; max 0 for (int i = 0; i < n; i++) {
      if (max < l[i]) {
        max = l[i];
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (max < l[i]) {
        max = l[i];
      }
    } {
      if (max < l[i]) {
        max = l[i];
      }
    } if (max < l[i]) {
        max = l[i];
      } max < l[i] max l[i] l i {
        max = l[i];
      } max = l[i] max l[i] l i if (n == 1) {
      System.out.println(max);
      return;
    } n == 1 n 1 {
      System.out.println(max);
      return;
    } System.out.println(max) System.out.println System.out System System.out max return; int count = 0; count 0 for (int i = max; i > 0; i--) {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    } int i = max; int i = max; i max i > 0 i 0 i-- i-- i {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    } {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    } for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      } int j = 0; int j = 0; j 0 j < n - 1 j n - 1 n 1 j++ j++ j {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      } {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      } if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        } l[j] == i l[j] l j i {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        } if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          } l[j + 1] == i l[j + 1] l j + 1 j 1 i {
            l[j]--;
          } l[j]-- l[j] l j {
            l[j]--;
            count++;
          } l[j]-- l[j] l j count++ count if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      } l[n - 1] == i l[n - 1] l n - 1 n 1 i {
        l[n - 1]--;
        count++;
      } l[n - 1]-- l[n - 1] l n - 1 n 1 count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] l = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = scanner.nextInt();
    }
    scanner.close();
    int max = 0;
    for (int i = 0; i < n; i++) {
      if (max < l[i]) {
        max = l[i];
      }
    }
    if (n == 1) {
      System.out.println(max);
      return;
    }
    int count = 0;
    for (int i = max; i > 0; i--) {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    }
    System.out.println(count);

  }

}
