#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    const int INF = 1001001001;
    int l = 0, r = INF;
    rep(i, n) {
        int a;
        cin >> a;
        l = max(l, a);
    }
    rep(i, n) {
        int b;
        cin >> b;
        r = min(r, b);
    }
    int ans = r-l+1;
    ans = max(0, ans);
    cout << ans << endl;

    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define all(x) sort(x.begin(),x.end())
#define int long long
#define pb push_back
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1e9+7
#define inf 1e18
#define garou99 ios_base::sync_with_stdio(false); cin.tie(NULL);
int pow(int p,int r,int m){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%m)*(p%m))%m;
	 }
	 r=r>>1;
     p=((p%m)*(p%m))%m;
	}
	return ans;
}
int32_t main(){
	garou99;
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int a[n],b[n];
	rep(i,0,n)
	cin>>a[i];
	rep(i,0,n)
	cin>>b[i];
    set<int> x;
    rep(i,a[0],b[0]+1)
    x.insert(i);
    rep(i,1,n){
    	set<int> s;
    	rep(j,a[i],b[i]+1)
    	s.insert(j);
    	set<int> an;
         for(auto j:s){
         	if(x.find(j)!=x.end())
         		an.insert(j);
    	}
    	x=an;
    }
    cout<<x.size();
}