import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] flowers = new int[N];
    for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    }

    Main abc116C = new Main();
    System.out.println(abc116C.solve(flowers));
  }

  public int solve(int[] flowers) {
    int ans = flowers[0];
    for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    }
    return 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 = sc.nextInt();
    int[] flowers = new int[N];
    for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    }

    Main abc116C = new Main();
    System.out.println(abc116C.solve(flowers));
  }

  public int solve(int[] flowers) {
    int ans = flowers[0];
    for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    }
    return ans;
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] flowers = new int[N];
    for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    }

    Main abc116C = new Main();
    System.out.println(abc116C.solve(flowers));
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] flowers = new int[N];
    for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    }

    Main abc116C = new Main();
    System.out.println(abc116C.solve(flowers));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] flowers = new int[N]; flowers new int[N] N for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      flowers[i] = sc.nextInt();
    } {
      flowers[i] = sc.nextInt();
    } flowers[i] = sc.nextInt() flowers[i] flowers i sc.nextInt() sc.nextInt sc Main abc116C = new Main(); abc116C new Main() System.out.println(abc116C.solve(flowers)) System.out.println System.out System System.out abc116C.solve(flowers) abc116C.solve abc116C flowers String[] args args public int solve(int[] flowers) {
    int ans = flowers[0];
    for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    }
    return ans;
  } solve {
    int ans = flowers[0];
    for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    }
    return ans;
  } int ans = flowers[0]; ans flowers[0] flowers 0 for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    } int i = 1; int i = 1; i 1 i < flowers.length i flowers.length flowers flowers.length i++ i++ i {
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    } {
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    } int delta = flowers[i] - flowers[i-1]; delta flowers[i] - flowers[i-1] flowers[i] flowers i flowers[i-1] flowers i-1 i 1 if(delta > 0) ans += delta; delta > 0 delta 0 ans += delta ans delta return ans; ans int[] flowers flowers public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] flowers = new int[N];
    for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    }

    Main abc116C = new Main();
    System.out.println(abc116C.solve(flowers));
  }

  public int solve(int[] flowers) {
    int ans = flowers[0];
    for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    }
    return ans;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] flowers = new int[N];
    for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    }

    Main abc116C = new Main();
    System.out.println(abc116C.solve(flowers));
  }

  public int solve(int[] flowers) {
    int ans = flowers[0];
    for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    }
    return ans;
  }
} 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[] flowers = new int[N];
    for(int i = 0; i < N; i++) {
      flowers[i] = sc.nextInt();
    }

    Main abc116C = new Main();
    System.out.println(abc116C.solve(flowers));
  }

  public int solve(int[] flowers) {
    int ans = flowers[0];
    for(int i = 1; i < flowers.length; i++ ){
      int delta = flowers[i] - flowers[i-1];
      if(delta > 0) ans += delta;
    }
    return ans;
  }
}
