#include<bits/stdc++.h> 
using namespace std;
const int mod=10;
using ll=long long;
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define pr(s) cout<<s<<"\n"

void solve(){
    int n;
    cin>>n;
    std::vector<int>a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin>>a[i];
    }
    for (int i = 0; i < n; i++) {
        cin>>b[i];
    }
    map<int,int>mp;
    for (int i = 0; i < n; i++) {
        for (int j = a[i]; j<=b[i]; j++) {
            mp[j]++;
        }
    }
    int ans=0;
    for(auto it:mp){
        if(it.second>=n){
            ans++;
        }
    }
    pr(ans);
}


int main(){
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("outputakash.txt", "w", stdout); 
  #else*/
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 // #endif
    int T=1;
    //cin>>T;
    ///int TEST=1;
    while(T--){
     // cout<<"Case #"<<TEST<<": ";
      solve();
      //TEST++;
    }
    return 0;        
}
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#define ll long long
using namespace std;
template<typename t1>
void print(vector<t1>& arr){
	for(t1 x:arr)
	    cout<<x<<" ";
	cout<<"\n";
}
template<typename t1>
void print(vector<vector<t1>>& arr){
	for(vector<t1> vec:arr){
		for(t1 x:vec)
		    cout<<x<<" ";
		cout<<"\n";
	}
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	int mn = *min_element(b.begin(),b.end());
	int mx = *max_element(a.begin(),a.end());
	cout<<((mn-mx+1)<0?0:mn-mx+1);
	return 0;
}
