import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] hana = new int[N]; hana new int[N] N for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i< N i N i++ i++ i {
			hana[i] = sc.nextInt();
		} {
			hana[i] = sc.nextInt();
		} hana[i] = sc.nextInt() hana[i] hana i sc.nextInt() sc.nextInt sc int water = 0; water 0 int max = hana[0]; max hana[0] hana 0 int maxnum = 0; maxnum 0 for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに int i = 0; int i = 0; i 0 i< N i N i++ i++ i {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		} if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			} max < hana[i] max hana[i] hana i {
				maxnum = i;
				max = hana[i];
			} maxnum = i maxnum i max = hana[i] max hana[i] hana i for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		} ; {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		} {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		} int nzmin =  100; nzmin 100 int divCnt = 0; divCnt 0 for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに int i = 0; int i = 0; i 0 i< N i N i++ i++ i {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			} if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				} nzmin > hana[i] && hana[i] > 0 nzmin > hana[i] nzmin hana[i] hana i hana[i] > 0 hana[i] hana i 0 {
					nzmin = hana[i];
				} nzmin = hana[i] nzmin hana[i] hana i boolean lastExit =false; lastExit false for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			} int i = 0; int i = 0; i 0 i< N i N i++ i++ i {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			} {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			} if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				} !(lastExit) &&hana[i] > 0 !(lastExit) (lastExit) hana[i] > 0 hana[i] hana i 0 {
					divCnt++;
					lastExit = true;
				} divCnt++ divCnt lastExit = true lastExit true if(hana[i] <= 0) {
					
					lastExit = false;
				} hana[i] <= 0 hana[i] hana i 0 {
					
					lastExit = false;
				} lastExit = false lastExit false water += (nzmin * divCnt) water (nzmin * divCnt) nzmin divCnt for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			} if(hana[i] > 0) {
					hana[i] -= nzmin;
				} hana[i] > 0 hana[i] hana i 0 {
					hana[i] -= nzmin;
				} hana[i] -= nzmin hana[i] hana i nzmin if(hana[maxnum] <= 0) {
				break;
			} hana[maxnum] <= 0 hana[maxnum] hana maxnum 0 {
				break;
			} break; System.out.println(water) System.out.println System.out System System.out water String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	}

}
