import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> list_line = new ArrayList<Integer>();
		int count = 0;
		int count_high = 0;
		boolean isChain = false;
		boolean until = true;
		boolean unfinish  =false;

		for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		}


		while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		}

		System.out.println(count);
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> list_line = new ArrayList<Integer>();
		int count = 0;
		int count_high = 0;
		boolean isChain = false;
		boolean until = true;
		boolean unfinish  =false;

		for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		}


		while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		}

		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> list_line = new ArrayList<Integer>();
		int count = 0;
		int count_high = 0;
		boolean isChain = false;
		boolean until = true;
		boolean unfinish  =false;

		for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		}


		while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		}

		System.out.println(count);
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> list_line = new ArrayList<Integer>();
		int count = 0;
		int count_high = 0;
		boolean isChain = false;
		boolean until = true;
		boolean unfinish  =false;

		for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		}


		while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		}

		System.out.println(count);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan ArrayList<Integer> list_line = new ArrayList<Integer>(); list_line new ArrayList<Integer>() int count = 0; count 0 int count_high = 0; count_high 0 boolean isChain = false; isChain false boolean until = true; until true boolean unfinish  =false; unfinish false for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			list_line.add(scan.nextInt());
		} {
			list_line.add(scan.nextInt());
		} list_line.add(scan.nextInt()) list_line.add list_line scan.nextInt() scan.nextInt scan while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		} until {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		} for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			} {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			} if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				} count_high >= list_line.get(i) count_high list_line.get(i) list_line.get list_line i {
					if(isChain) {
						isChain = false;
						count++;
					}

				} if(isChain) {
						isChain = false;
						count++;
					} isChain {
						isChain = false;
						count++;
					} isChain = false isChain false count++ count {
					if(!isChain) {
						isChain = true;
					}
				} if(!isChain) {
						isChain = true;
					} !isChain isChain {
						isChain = true;
					} isChain = true isChain true count_high++ count_high for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			} {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			} if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				} count_high < list_line.get(i) count_high list_line.get(i) list_line.get list_line i {
					unfinish = true;
					break;
				} unfinish = true unfinish true break; if(!unfinish) {
				until = false;
			} !unfinish unfinish {
				until = false;
			} until = false until false if(isChain) {
				isChain = false;
				count++;
			} isChain {
				isChain = false;
				count++;
			} isChain = false isChain false count++ count unfinish = false unfinish false 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 scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> list_line = new ArrayList<Integer>();
		int count = 0;
		int count_high = 0;
		boolean isChain = false;
		boolean until = true;
		boolean unfinish  =false;

		for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		}


		while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		}

		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> list_line = new ArrayList<Integer>();
		int count = 0;
		int count_high = 0;
		boolean isChain = false;
		boolean until = true;
		boolean unfinish  =false;

		for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		}


		while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		}

		System.out.println(count);
	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> list_line = new ArrayList<Integer>();
		int count = 0;
		int count_high = 0;
		boolean isChain = false;
		boolean until = true;
		boolean unfinish  =false;

		for(int i = 0;i < n;i++) {
			list_line.add(scan.nextInt());
		}


		while(until) {
			for(int i = 0;i < n;i++) {
				if(count_high >= list_line.get(i)) {
					if(isChain) {
						isChain = false;
						count++;
					}

				}else {
					if(!isChain) {
						isChain = true;
					}
				}
			}
			count_high++;

			for(int i = 0;i < n;i++) {
				if(count_high < list_line.get(i)) {
					unfinish = true;
					break;
				}
			}

			if(!unfinish) {
				until = false;
			}

			if(isChain) {
				isChain = false;
				count++;
			}
			unfinish = false;
		}

		System.out.println(count);
	}
}
