import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		}
		int count = 0;
		int ans = 0;
		for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		}
		System.out.println(ans);
		sc.close();
	}
} 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[] h = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		}
		int count = 0;
		int ans = 0;
		for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		}
		System.out.println(ans);
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		}
		int count = 0;
		int ans = 0;
		for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		}
		System.out.println(ans);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		}
		int count = 0;
		int ans = 0;
		for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		}
		System.out.println(ans);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n int max = 0; max 0 for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		} {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc max = Math.max(max,h[i]) max Math.max(max,h[i]) Math.max Math max h[i] h i int count = 0; count 0 int ans = 0; ans 0 for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		} int i = 1; int i = 1; i 1 i <= max i max i++ i++ i {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		} {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		} count = 0 count 0 for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			} {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			} if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				} h[j]>0 h[j] h j 0 {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				} if(j==0) count++;
					else if(h[j-1] == 0) count++; j==0 j 0 count++ count if(h[j-1] == 0) count++; h[j-1] == 0 h[j-1] h j-1 j 1 0 count++ count for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
				if(h[j]>0) h[j]-=1;
			} {
				if(h[j]>0) h[j]-=1;
			} if(h[j]>0) h[j]-=1; h[j]>0 h[j] h j 0 h[j]-=1 h[j] h j 1 ans += count ans count System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		}
		int count = 0;
		int ans = 0;
		for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		}
		System.out.println(ans);
		sc.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		}
		int count = 0;
		int ans = 0;
		for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		}
		System.out.println(ans);
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			max = Math.max(max,h[i]);
		}
		int count = 0;
		int ans = 0;
		for (int i = 1; i <= max; i++) {
			count = 0;
			for (int j = 0; j < n; j++) {
				if(h[j]>0) {
					if(j==0) count++;
					else if(h[j-1] == 0) count++;
				}
			}
			for (int j = 0; j < n; j++) {
				if(h[j]>0) h[j]-=1;
			}
			ans += count;
		}
		System.out.println(ans);
		sc.close();
	}
}