import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  }
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  }
} Main public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  } main {
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  } try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    } catch (Exception e) {
      System.out.println("out");
    } Exception e {
      System.out.println("out");
    } System.out.println("out") System.out.println System.out System System.out "out" {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n ans=0; ans 0 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 for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      } {
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      } if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        } h[i]>h[i+1] h[i] h i h[i+1] h i+1 i 1 {
          ans=ans+h[i]-h[i+1];
        } ans=ans+h[i]-h[i+1] ans ans+h[i]-h[i+1] ans+h[i] ans h[i] h i h[i+1] h i+1 i 1 System.out.println(ans+h[n-1]) System.out.println System.out System System.out ans+h[n-1] ans h[n-1] h n-1 n 1 String[] args args public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  }
} public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  }
} Main
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  }
}
