import java.util.Arrays;
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 + 1];
		int[] hs = new int[N + 1];
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		}
		
		int count = 0;
		Arrays.sort(hs);
		
		for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
} import java.util.Arrays; Arrays java.util 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 + 1];
		int[] hs = new int[N + 1];
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		}
		
		int count = 0;
		Arrays.sort(hs);
		
		for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] h = new int[N + 1];
		int[] hs = new int[N + 1];
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		}
		
		int count = 0;
		Arrays.sort(hs);
		
		for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] h = new int[N + 1];
		int[] hs = new int[N + 1];
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		}
		
		int count = 0;
		Arrays.sort(hs);
		
		for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	} 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 + 1]; h new int[N + 1] N + 1 N 1 int[] hs = new int[N + 1]; hs new int[N + 1] N + 1 N 1 int[] x = new int[N + 1]; x new int[N + 1] N + 1 N 1 for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		} {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc hs[i] = h[i] hs[i] hs i h[i] h i x[i] = 0 x[i] x i 0 int count = 0; count 0 Arrays.sort(hs) Arrays.sort Arrays hs for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		} int j = 1; int j = 1; j 1 j <= hs[N] j hs[N] hs N j++ j++ j {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		} {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		} for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			} {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			} if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				} x[i] < h[i] x[i] x i h[i] h i {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				} x[i] += 1 x[i] x i 1 if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					} i == N || x[i + 1] == h[i + 1] i == N i N x[i + 1] == h[i + 1] x[i + 1] x i + 1 i 1 h[i + 1] h i + 1 i 1 {
						count++;
					} count++ count System.out.println(count) System.out.println System.out System System.out count 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 + 1];
		int[] hs = new int[N + 1];
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		}
		
		int count = 0;
		Arrays.sort(hs);
		
		for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] h = new int[N + 1];
		int[] hs = new int[N + 1];
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		}
		
		int count = 0;
		Arrays.sort(hs);
		
		for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Arrays;
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 + 1];
		int[] hs = new int[N + 1];
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			h[i] = sc.nextInt();
			hs[i] = h[i];
			x[i] = 0;
		}
		
		int count = 0;
		Arrays.sort(hs);
		
		for(int j = 1; j <= hs[N]; j++) {
			for(int i = 1; i <= N; i++) {
				if(x[i] < h[i]) {
					x[i] += 1;
					if(i == N || x[i + 1] == h[i + 1]) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}
