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

class Main {
	public static void main(String args[]) {
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int i = 0;
        while( i < n) {
            a[i] = s.nextInt();
            i++;
        }
        i = 0;
        int ans = 0;
        int prev = 0;
        while( i < n) {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        }
        System.out.println(ans);
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {
	public static void main(String args[]) {
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int i = 0;
        while( i < n) {
            a[i] = s.nextInt();
            i++;
        }
        i = 0;
        int ans = 0;
        int prev = 0;
        while( i < n) {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        }
        System.out.println(ans);
    }
} Main public static void main(String args[]) {
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int i = 0;
        while( i < n) {
            a[i] = s.nextInt();
            i++;
        }
        i = 0;
        int ans = 0;
        int prev = 0;
        while( i < n) {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        }
        System.out.println(ans);
    } main {
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int i = 0;
        while( i < n) {
            a[i] = s.nextInt();
            i++;
        }
        i = 0;
        int ans = 0;
        int prev = 0;
        while( i < n) {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        }
        System.out.println(ans);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int[] a = new int[n]; a new int[n] n int i = 0; i 0 while( i < n) {
            a[i] = s.nextInt();
            i++;
        } i < n i n {
            a[i] = s.nextInt();
            i++;
        } a[i] = s.nextInt() a[i] a i s.nextInt() s.nextInt s i++ i i = 0 i 0 int ans = 0; ans 0 int prev = 0; prev 0 while( i < n) {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        } i < n i n {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        } while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            } i+1 < n && a[i+1] >= a[i] i+1 < n i+1 i 1 n a[i+1] >= a[i] a[i+1] a i+1 i 1 a[i] a i {
                i++;
            } i++ i ans += a[i] - prev ans a[i] - prev a[i] a i prev while(i+1 < n && a[i+1] < a[i]) {
                i++;
            } i+1 < n && a[i+1] < a[i] i+1 < n i+1 i 1 n a[i+1] < a[i] a[i+1] a i+1 i 1 a[i] a i {
                i++;
            } i++ i prev = a[i] prev a[i] a i if(i+1 == n) break; i+1 == n i+1 i 1 n break; System.out.println(ans) System.out.println System.out System System.out ans String args[] args
import java.io.*;
import java.util.*;

class Main {
	public static void main(String args[]) {
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int i = 0;
        while( i < n) {
            a[i] = s.nextInt();
            i++;
        }
        i = 0;
        int ans = 0;
        int prev = 0;
        while( i < n) {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        }
        System.out.println(ans);
    }
}