import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int old=0,ans=0;
        int m=0;
        for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        }
        System.out.println(ans+m);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int old=0,ans=0;
        int m=0;
        for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        }
        System.out.println(ans+m);
    }
} Main public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int old=0,ans=0;
        int m=0;
        for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        }
        System.out.println(ans+m);
    } main {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int old=0,ans=0;
        int m=0;
        for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        }
        System.out.println(ans+m);
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int old=0 old 0 ans=0; ans 0 int m=0; m 0 for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        } {
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        } m=sc.nextInt() m sc.nextInt() sc.nextInt sc if(old>m){
                ans+=old-m;
            } old>m old m {
                ans+=old-m;
            } ans+=old-m ans old-m old m old=m old m System.out.println(ans+m) System.out.println System.out System System.out ans+m ans m String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int old=0,ans=0;
        int m=0;
        for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        }
        System.out.println(ans+m);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int old=0,ans=0;
        int m=0;
        for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        }
        System.out.println(ans+m);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int old=0,ans=0;
        int m=0;
        for(int i=0;i<n;i++){
            m=sc.nextInt();
            if(old>m){
                ans+=old-m;
            }
            old=m;
        }
        System.out.println(ans+m);
    }
}
