import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

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

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

    System.out.println(ans);
  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

    System.out.println(ans);
  } main {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

    System.out.println(ans);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int h[] = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      h[i] = Integer.parseInt(sc.next());
    } {
      h[i] = Integer.parseInt(sc.next());
    } h[i] = Integer.parseInt(sc.next()) h[i] h i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc long ans = 0; ans 0 while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    } true {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    } int s = -1; s -1 1 for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        if (h[i] > 0) {
          s = i;
          break;
        }
      } {
        if (h[i] > 0) {
          s = i;
          break;
        }
      } if (h[i] > 0) {
          s = i;
          break;
        } h[i] > 0 h[i] h i 0 {
          s = i;
          break;
        } s = i s i break; if (s < 0) {
        break;
      } s < 0 s 0 {
        break;
      } break; ans++ ans for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      } int i = s; int i = s; i s i < N i N i++ i++ i {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      } {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      } if(h[i]>0) {
          h[i]--;
        }else {
          break;
        } h[i]>0 h[i] h i 0 {
          h[i]--;
        } h[i]-- h[i] h i {
          break;
        } break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

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

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

    System.out.println(ans);
  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

    System.out.println(ans);
  }
}
