import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); in.nextLine();
        String[] tmp = in.nextLine().split(" ");
        int[] ary = new int[n+1];
        for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]);
        int ans = 0;
        for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); in.nextLine();
        String[] tmp = in.nextLine().split(" ");
        int[] ary = new int[n+1];
        for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]);
        int ans = 0;
        for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); in.nextLine();
        String[] tmp = in.nextLine().split(" ");
        int[] ary = new int[n+1];
        for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]);
        int ans = 0;
        for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        }
        System.out.println(ans);
    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); in.nextLine();
        String[] tmp = in.nextLine().split(" ");
        int[] ary = new int[n+1];
        for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]);
        int ans = 0;
        for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        }
        System.out.println(ans);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in in.nextLine() in.nextLine in String[] tmp = in.nextLine().split(" "); tmp in.nextLine().split(" ") in.nextLine().split in.nextLine() in.nextLine in " " int[] ary = new int[n+1]; ary new int[n+1] n+1 n 1 for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]); int i = 1; int i = 1; i 1 i <= n i n i++ i++ i ary[i] = Integer.parseInt(tmp[i-1]); ary[i] = Integer.parseInt(tmp[i-1]) ary[i] ary i Integer.parseInt(tmp[i-1]) Integer.parseInt Integer tmp[i-1] tmp i-1 i 1 int ans = 0; ans 0 for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        } int i = 1; int i = 1; i 1 i < n+1 i n+1 n 1 i++ i++ i {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        } {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        } if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1]; ary[i]-ary[i-1]>0 ary[i]-ary[i-1] ary[i] ary i ary[i-1] ary i-1 i 1 0 ans += ary[i]-ary[i-1] ans ary[i]-ary[i-1] ary[i] ary i ary[i-1] ary i-1 i 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); in.nextLine();
        String[] tmp = in.nextLine().split(" ");
        int[] ary = new int[n+1];
        for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]);
        int ans = 0;
        for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); in.nextLine();
        String[] tmp = in.nextLine().split(" ");
        int[] ary = new int[n+1];
        for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]);
        int ans = 0;
        for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        }
        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); in.nextLine();
        String[] tmp = in.nextLine().split(" ");
        int[] ary = new int[n+1];
        for( int i = 1; i <= n; i++ ) ary[i] = Integer.parseInt(tmp[i-1]);
        int ans = 0;
        for( int i = 1; i < n+1; i++ ) {
            if( ary[i]-ary[i-1]>0 ) ans += ary[i]-ary[i-1];
        }
        System.out.println(ans);
    }
}