import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	} main {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	} int i; i 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(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		} i=0; i=0 i 0 i<n i n i++ i++ i {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		} {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc if(max < h[i]) max = h[i]; max < h[i] max h[i] h i max = h[i] max h[i] h i sc.close() sc.close sc sc = null sc null int ans = 0; ans 0 for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		} i=1; i=1 i 1 i<=max i max i++ i++ i {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		} {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		} boolean f = false; f false for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			} int j=0; int j=0; j 0 j<n j n j++ j++ j {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			} {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			} if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;} !f && h[j] >= i !f f h[j] >= i h[j] h j i {ans++;f = true;} ans++ ans f = true f true if(f &&  h[j] < i) {f = false;} f &&  h[j] < i f h[j] < i h[j] h j i {f = false;} f = false f false System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	}
}
