import java.util.Scanner;

/**
 * 
 * @author morisin
 * 
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 花の数
		int N = sc.nextInt();

		// 一つ手前の花の高さ
		int prev = 0;
		
		// 水やり回数
		int cnt = 0;
		
		// 花の高さの入力
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		}
		cnt+=prev;
		
		System.out.println(cnt);
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 花の数
		int N = sc.nextInt();

		// 一つ手前の花の高さ
		int prev = 0;
		
		// 水やり回数
		int cnt = 0;
		
		// 花の高さの入力
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		}
		cnt+=prev;
		
		System.out.println(cnt);
	}

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

		// 花の数
		int N = sc.nextInt();

		// 一つ手前の花の高さ
		int prev = 0;
		
		// 水やり回数
		int cnt = 0;
		
		// 花の高さの入力
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		}
		cnt+=prev;
		
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);

		// 花の数
		int N = sc.nextInt();

		// 一つ手前の花の高さ
		int prev = 0;
		
		// 水やり回数
		int cnt = 0;
		
		// 花の高さの入力
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		}
		cnt+=prev;
		
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int prev = 0; prev 0 int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		} {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		} int h = sc.nextInt(); h sc.nextInt() sc.nextInt sc if (h < prev)
				cnt += prev - h; h < prev h prev cnt += prev - h cnt prev - h prev h prev = h prev h cnt+=prev cnt prev System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 花の数
		int N = sc.nextInt();

		// 一つ手前の花の高さ
		int prev = 0;
		
		// 水やり回数
		int cnt = 0;
		
		// 花の高さの入力
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		}
		cnt+=prev;
		
		System.out.println(cnt);
	}

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

		// 花の数
		int N = sc.nextInt();

		// 一つ手前の花の高さ
		int prev = 0;
		
		// 水やり回数
		int cnt = 0;
		
		// 花の高さの入力
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		}
		cnt+=prev;
		
		System.out.println(cnt);
	}

} Main
import java.util.Scanner;

/**
 * 
 * @author morisin
 * 
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 花の数
		int N = sc.nextInt();

		// 一つ手前の花の高さ
		int prev = 0;
		
		// 水やり回数
		int cnt = 0;
		
		// 花の高さの入力
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h < prev)
				cnt += prev - h;
			prev = h;
		}
		cnt+=prev;
		
		System.out.println(cnt);
	}

}
