import java.util.*;
 
public class Main {
  static int n;
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {
  static int n;
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    }
} Main static int n; n public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    } main {
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE 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 ans = 0; ans 0 int active = 0; active 0 for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      } {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      } if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        } active >= h[i] active h[i] h i {
          active = h[i];
        } active = h[i] active h[i] h i {
          ans += h[i] - active;
          active = h[i];
        } ans += h[i] - active ans h[i] - active h[i] h i active active = h[i] active h[i] h i System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  static int n;
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    }
} public class Main {
  static int n;
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    }
} Main
import java.util.*;
 
public class Main {
  static int n;
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    }
}