#include <iostream>
#include <bits/stdc++.h>


using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> A;
	vector<int> B;
	for (int i = 0; i < N; i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
	for (int i = 0; i < N; i++){
		int b;
		cin >> b;
		B.push_back(b);
	}
	
	int minn = A[0];
	int maxx = B[0];
	
	for (int i = 1; i < N; i++){
		minn = max(minn, A[i]);
		maxx = min(maxx, B[i]);
	}
	if (maxx >= minn)
		cout << maxx-minn+1;
	else
		cout << 0;
}

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A[1000000];
    cin >> N;
    int size = 1 << N;
    REP(i, size) cin >> A[i];

    int half = size / 2;
    int maxi1 = max_element(A, A + half) - A, maxi2 = max_element(A + half, A + size) - A;
    if (A[maxi1] > A[maxi2]) cout << maxi2 + 1 << endl;
    else cout << maxi1 + 1 << endl;
    return 0;
}