// Arup Guha
// 3/9/2024
// Solution to Kattis Problem: Free Weights
// https://open.kattis.com/problems/freeweights

import java.util.*;
import java.io.*;

public class freeweights {

	public static int n;
	public static int[] row1;
	public static int[] row2;
	public static int max;
	
	public static void main(String[] args) throws Exception {
	
		// Set up storage for both rows.
		FastScanner stdin = new FastScanner(System.in);
		n = stdin.nextInt();
		row1 = new int[n];
		row2 = new int[n];
		max = 0;
		
		// Read row 1.
		for (int i=0; i<n; i++) {
			row1[i] = stdin.nextInt();
			max = Math.max(max, row1[i]);
		}
			
		// Read row 2.
		for (int i=0; i<n; i++) {
			row2[i] = stdin.nextInt();
			max = Math.max(max, row2[i]);
		}
		
		// Solve it.
		System.out.println(solve());
	}
	
	// Returns the solution via binary sesarch.
	public static int solve() {
	
		// Safe bounds...
		int low = 0, high = max;
		
		// Integer binary search must converge on a single value.
		while (low < high) {
		
			int mid = (low+high)/2;
			
			// If it works, this is the highest the answer could be.
			if (canDo(mid))
				high = mid;
			
			// It doesn't work so the lowest the answer could be is mid+1.
			else
				low = mid+1;
		}
		
		// Ta da!
		return low;
	}
	
	// We can do it only if both rows are good.
	public static boolean canDo(int lift) {
		return canDo(lift, row1) && canDo(lift, row2);
	}
	
	public static boolean canDo(int lift, int[] items) {
				
		int prev = -1, curL = 0;
		
		// Go through the list.
		for (int i=0; i<n; i++) {
			
			// We can lift it...
			if (items[i] <= lift) continue;
			
			// We are in a string of too heavy items.
			if (curL == 1) {
				
				// If this doesn't match we can't do it.
				if (items[i] != prev) return false;
				
				// Reset since the matching pair is together.
				curL = 0;
			}
			
			// Indicate we got to something too heavy.
			else {
				curL = 1;
			}
			
			// Store where our too heavy item is.
			prev = items[i];
		}
		
		// We're good as long as there isn't a leftover item.
		return curL == 0;
	}
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;
	
    public FastScanner(InputStream i) {
        br = new BufferedReader(new InputStreamReader(i));
        st = new StringTokenizer("");
    }
			
    public String next() throws IOException {
        if(st.hasMoreTokens())
            return st.nextToken();
        else
            st = new StringTokenizer(br.readLine());
        return next();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    //#
    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    //$
}
