import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] mizu=new int[N];
		int min=888;
		for(int i=0; i<N; i++) {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		}
		int ans=min;
		for(int i=0; i<N; i++) {
			mizu[i]-=min;
		}

		while(ok(mizu)) {
			int kaisi=0;
			int owari=0;
			boolean mi=false;
			for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			}
			min=888;
			for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			}
			for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			}
			ans+=min;
		}
		pl(ans);
	}

 	public static boolean ok(int[] a) {
 		for(int i=0; i<a.length; i++) {
 			if(a[i]!=0) {
 				return true;
 			}
 		}
 		return false;
 	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.UncheckedIOException; UncheckedIOException java.io import java.util.StringTokenizer; StringTokenizer java.util class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] mizu=new int[N];
		int min=888;
		for(int i=0; i<N; i++) {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		}
		int ans=min;
		for(int i=0; i<N; i++) {
			mizu[i]-=min;
		}

		while(ok(mizu)) {
			int kaisi=0;
			int owari=0;
			boolean mi=false;
			for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			}
			min=888;
			for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			}
			for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			}
			ans+=min;
		}
		pl(ans);
	}

 	public static boolean ok(int[] a) {
 		for(int i=0; i<a.length; i++) {
 			if(a[i]!=0) {
 				return true;
 			}
 		}
 		return false;
 	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
} Main public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] mizu=new int[N];
		int min=888;
		for(int i=0; i<N; i++) {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		}
		int ans=min;
		for(int i=0; i<N; i++) {
			mizu[i]-=min;
		}

		while(ok(mizu)) {
			int kaisi=0;
			int owari=0;
			boolean mi=false;
			for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			}
			min=888;
			for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			}
			for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			}
			ans+=min;
		}
		pl(ans);
	} main {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] mizu=new int[N];
		int min=888;
		for(int i=0; i<N; i++) {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		}
		int ans=min;
		for(int i=0; i<N; i++) {
			mizu[i]-=min;
		}

		while(ok(mizu)) {
			int kaisi=0;
			int owari=0;
			boolean mi=false;
			for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			}
			min=888;
			for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			}
			for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			}
			ans+=min;
		}
		pl(ans);
	} SC sc=new SC(System.in); sc new SC(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] mizu=new int[N]; mizu new int[N] N int min=888; min 888 for(int i=0; i<N; i++) {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		} {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		} mizu[i]=sc.nextInt() mizu[i] mizu i sc.nextInt() sc.nextInt sc min=Math.min(mizu[i], min) min Math.min(mizu[i], min) Math.min Math mizu[i] mizu i min int ans=min; ans min for(int i=0; i<N; i++) {
			mizu[i]-=min;
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			mizu[i]-=min;
		} {
			mizu[i]-=min;
		} mizu[i]-=min mizu[i] mizu i min while(ok(mizu)) {
			int kaisi=0;
			int owari=0;
			boolean mi=false;
			for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			}
			min=888;
			for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			}
			for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			}
			ans+=min;
		} ok(mizu) ok mizu {
			int kaisi=0;
			int owari=0;
			boolean mi=false;
			for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			}
			min=888;
			for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			}
			for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			}
			ans+=min;
		} int kaisi=0; kaisi 0 int owari=0; owari 0 boolean mi=false; mi false for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			} int i=0; int i=0; i 0 i<N i N i++ i++ i {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			} {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			} if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				} !mi mi {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				} if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					} mizu[i]>0 mizu[i] mizu i 0 {
						kaisi=i;
						owari=i;
						mi=true;
					} kaisi=i kaisi i owari=i owari i mi=true mi true {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				} if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					} mizu[i]>0 mizu[i] mizu i 0 {
						owari=i;
					} owari=i owari i if(mizu[i]==0) {
						break;
					} mizu[i]==0 mizu[i] mizu i 0 {
						break;
					} break; min=888 min 888 for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			} int unko=kaisi; int unko=kaisi; unko kaisi unko<=owari unko owari unko++ unko++ unko {
				min=Math.min(min, mizu[unko]);
			} {
				min=Math.min(min, mizu[unko]);
			} min=Math.min(min, mizu[unko]) min Math.min(min, mizu[unko]) Math.min Math min mizu[unko] mizu unko for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			} int unko=kaisi; int unko=kaisi; unko kaisi unko<=owari unko owari unko++ unko++ unko {
				mizu[unko]-=min;
			} {
				mizu[unko]-=min;
			} mizu[unko]-=min mizu[unko] mizu unko min ans+=min ans min pl(ans) pl ans String[] args args public static boolean ok(int[] a) {
 		for(int i=0; i<a.length; i++) {
 			if(a[i]!=0) {
 				return true;
 			}
 		}
 		return false;
 	} ok {
 		for(int i=0; i<a.length; i++) {
 			if(a[i]!=0) {
 				return true;
 			}
 		}
 		return false;
 	} for(int i=0; i<a.length; i++) {
 			if(a[i]!=0) {
 				return true;
 			}
 		} int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
 			if(a[i]!=0) {
 				return true;
 			}
 		} {
 			if(a[i]!=0) {
 				return true;
 			}
 		} if(a[i]!=0) {
 				return true;
 			} a[i]!=0 a[i] a i 0 {
 				return true;
 			} return true; true return false; false int[] a a public static void pl(Object o) {
		System.out.println(o);
	} pl {
		System.out.println(o);
	} System.out.println(o) System.out.println System.out System System.out o Object o o public static void pl() {
		System.out.println();
	} pl {
		System.out.println();
	} System.out.println() System.out.println System.out System System.out public static void p(Object o) {
		System.out.print(o);
	} p {
		System.out.print(o);
	} System.out.print(o) System.out.print System.out System System.out o Object o o static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	} SC private BufferedReader reader = null; reader null private StringTokenizer tokenizer = null; tokenizer null public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		} SC {
			reader = new BufferedReader(new InputStreamReader(in));
		} reader = new BufferedReader(new InputStreamReader(in)) reader new BufferedReader(new InputStreamReader(in)) InputStream in in public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		} next {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		} if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			} tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			} try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				} IOException e {
					throw new UncheckedIOException(e);
				} throw new UncheckedIOException(e); new UncheckedIOException(e) {
					tokenizer = new StringTokenizer(reader.readLine());
				} tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public int nextInt() {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() {
			return Long.parseLong(next());
		} nextLong {
			return Long.parseLong(next());
		} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {
			return Double.parseDouble(next());
		} nextDouble {
			return Double.parseDouble(next());
		} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		} nextLine {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		} try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			} IOException e {
				throw new UncheckedIOException(e);
			} throw new UncheckedIOException(e); new UncheckedIOException(e) {
				return reader.readLine();
			} return reader.readLine(); reader.readLine() reader.readLine reader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] mizu=new int[N];
		int min=888;
		for(int i=0; i<N; i++) {
			mizu[i]=sc.nextInt();
			min=Math.min(mizu[i], min);
		}
		int ans=min;
		for(int i=0; i<N; i++) {
			mizu[i]-=min;
		}

		while(ok(mizu)) {
			int kaisi=0;
			int owari=0;
			boolean mi=false;
			for(int i=0; i<N; i++) {
				if(!mi) {		//まだ水やりの場所を確定させていない
					if(mizu[i]>0) {
						kaisi=i;
						owari=i;
						mi=true;
					}
				}
				else {
					if(mizu[i]>0) {
						owari=i;
					}
					else if(mizu[i]==0) {
						break;
					}
				}
			}
			min=888;
			for(int unko=kaisi; unko<=owari; unko++) {
				min=Math.min(min, mizu[unko]);
			}
			for(int unko=kaisi; unko<=owari; unko++) {
				mizu[unko]-=min;
			}
			ans+=min;
		}
		pl(ans);
	}

 	public static boolean ok(int[] a) {
 		for(int i=0; i<a.length; i++) {
 			if(a[i]!=0) {
 				return true;
 			}
 		}
 		return false;
 	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}