#include<bits/stdc++.h>
using namespace std;

#define maxn 105
typedef long long ll;
ll n,a[maxn],b[maxn];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++) cin>>b[i];
	ll counter=0;
	for(int i=1;i<=1000;i++){
		bool flag=false;
		for(int j=1;j<=n;j++)
			if(! (a[j]<=i && i<=b[j]))
				flag=true;
		if(!flag) counter++;
	}
	cout<<counter<<endl;
	return 0;
}
/*
 * Lang  : C++ 17
 * Author: Debajyoti Dasgupta
 * Date  : 10-04-2021 23:37 10
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int mod = 1000'000'007;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;
    int mn = 0, mx = 1e9;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mn = max(mn, x);
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mx = min(mx, x);
    }
    cout << max(0, mx - mn + 1) << endl;
}
