import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int num = Integer.parseInt(scanner.nextLine());

		List<Integer> h = new ArrayList<Integer>();

		for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		}

		int times = 0;
		int preH = 0;
		int min = 0;

		for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		}
		times += preH - min;

		System.out.println(times);
	}

} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int num = Integer.parseInt(scanner.nextLine());

		List<Integer> h = new ArrayList<Integer>();

		for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		}

		int times = 0;
		int preH = 0;
		int min = 0;

		for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		}
		times += preH - min;

		System.out.println(times);
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int num = Integer.parseInt(scanner.nextLine());

		List<Integer> h = new ArrayList<Integer>();

		for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		}

		int times = 0;
		int preH = 0;
		int min = 0;

		for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		}
		times += preH - min;

		System.out.println(times);
	} main {
		Scanner scanner = new Scanner(System.in);

		int num = Integer.parseInt(scanner.nextLine());

		List<Integer> h = new ArrayList<Integer>();

		for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		}

		int times = 0;
		int preH = 0;
		int min = 0;

		for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		}
		times += preH - min;

		System.out.println(times);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int num = Integer.parseInt(scanner.nextLine()); num Integer.parseInt(scanner.nextLine()) Integer.parseInt Integer scanner.nextLine() scanner.nextLine scanner List<Integer> h = new ArrayList<Integer>(); h new ArrayList<Integer>() for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			h.add(Integer.parseInt(scanner.next()));
		} {
			h.add(Integer.parseInt(scanner.next()));
		} h.add(Integer.parseInt(scanner.next())) h.add h Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int times = 0; times 0 int preH = 0; preH 0 int min = 0; min 0 for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		} int tmp h {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		} {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		} if (tmp < preH) {
				times += preH - min;
				min = tmp;
			} tmp < preH tmp preH {
				times += preH - min;
				min = tmp;
			} times += preH - min times preH - min preH min min = tmp min tmp preH = tmp preH tmp times += preH - min times preH - min preH min System.out.println(times) System.out.println System.out System System.out times String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int num = Integer.parseInt(scanner.nextLine());

		List<Integer> h = new ArrayList<Integer>();

		for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		}

		int times = 0;
		int preH = 0;
		int min = 0;

		for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		}
		times += preH - min;

		System.out.println(times);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int num = Integer.parseInt(scanner.nextLine());

		List<Integer> h = new ArrayList<Integer>();

		for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		}

		int times = 0;
		int preH = 0;
		int min = 0;

		for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		}
		times += preH - min;

		System.out.println(times);
	}

} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int num = Integer.parseInt(scanner.nextLine());

		List<Integer> h = new ArrayList<Integer>();

		for (int i = 0; i < num; i++) {
			h.add(Integer.parseInt(scanner.next()));
		}

		int times = 0;
		int preH = 0;
		int min = 0;

		for (int tmp : h) {
			if (tmp < preH) {
				times += preH - min;
				min = tmp;
			}
			preH = tmp;
		}
		times += preH - min;

		System.out.println(times);
	}

}
