
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  }
} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  }
} Main public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  } main {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  } 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 max = 0; max 0 for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    } {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc max = Math.max(max, h[i]) max Math.max(max, h[i]) Math.max Math max h[i] h i int cnt = 0; cnt 0 for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    } int i = 0; int i = 0; i 0 i < max i max i++ i++ i {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    } {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    } boolean on = false; on false for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      } {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      } if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        } h[j] - i > 0 h[j] - i h[j] h j i 0 {
          if (!on) {
            on = true;
            cnt++;
          }
        } if (!on) {
            on = true;
            cnt++;
          } !on on {
            on = true;
            cnt++;
          } on = true on true cnt++ cnt {
          on = false;
        } on = false on false System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  }
} public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  }
} Main

import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  }
}
