// 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 {
	
		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]);
		}
			
		// And row 2.
		for (int i=0; i<n; i++) {
			row2[i] = stdin.nextInt();
			max = Math.max(max, row2[i]);
		}
		
		// Solve.
		System.out.println(solve());
	}
	
	public static int solve() {
	
		// Run a binary search on what you have to lift.
		int low = 0, high = max;
		
		// Run till we converge on an answer.
		while (low < high) {
		
			// Go halfway.
			int mid = (low+high)/2;
			
			// We can do it, the answer is no higher than mid.
			if (canDo(mid))
				high = mid;
			
			// We can't, the answer is mid+1 or greater.
			else
				low = mid+1;
		}
		
		// Ta da!
		return low;
	}
	
	// We can do it if both rows work.
	public static boolean canDo(int lift) {
		return canDo(lift, row1) && canDo(lift, row2);
	}
	
	// Returns true iff we can do the row listed in items lifting lift or less only.
	public static boolean canDo(int lift, int[] items) {
				
		int prev = -1, curL = 0;
		
		// Go through the weights.
		for (int i=0; i<n; i++) {
			
			// We can lift this so we can put this anywhere, it's good.
			if (items[i] <= lift) continue;
			
			// We previosuly saw an item, the next one must match this...
			if (curL == 1) {
				
				// It doesn't match, can't do it.
				if (items[i] != prev) return false;
				
				// We're back to having nothing to match.
				curL = 0;
			}
			
			// Now we have something to match.
			else {
				curL = 1;
			}
			
			// Store the previous value.
			prev = items[i];
		}
		
		// We're only good if there's nothing to match now.
		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());
    }
    //$
}
