#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;cin>>n;
	vector<ll>a(n),b(n);
	for(ll i=0;i<n;++i)
	{
		cin>>a[i];
	}
	for(ll i=0;i<n;++i)
	{
		cin>>b[i];
	}
	ll l=a[0],r=b[0];
	for(ll i=1;i<n;++i)
	{
		if(a[i]>l)
		{
			l=a[i];
		}
		if(b[i]<r)
		{
			r=b[i];
		}
	}
	if(l<=r)
	cout<<r-l+1<<"\n";
	else cout<<"0\n";
}
// Date-- 24/04/2021
//practice
#include <bits/stdc++.h>
using namespace std;

typedef  long long     ll;
typedef  vector<int>   vi;
typedef  pair<int,int> pii;

#define   all(x)        (x).begin(),(x).end()
#define   rep(i,a,b)    for(ll i = a; i<b ; i++)
#define   sz(x)         (int)((x).size())
#define   PI             3.141592653589
#define   mod            1000000007 
#define   MAX            1000001 //1e6+1
long long const INF = 1e18;

void cf()
{
    ll n; cin>>n;
    ll a[n],b[n];
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) cin>>b[i];
    ll x = *max_element(a,a+n);
    ll y = *min_element(b,b+n);
    ll ans = y-x+1;
    if(ans<=0) cout<<0;
    else cout<<ans;
}

int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);cout.tie(NULL);
    int T=1; //cin>>T;
    while(T--)  cf();
    return 0;
}