public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

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

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

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

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

    public static void main(String[] args) {
        int n=scanner.nextInt(),last=0,ans=0;
        for(int i=0,j;i<n;i++,last=j)if(last>=(j=scanner.nextInt()))ans+=last-j;
        System.out.println(last+ans);
    }
}