#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    ll a[n]; zep(i, 0, n)cin >> a[i];
    ll b[n]; zep(i, 0, n)cin >> b[i];

    ll mx = INF, mn = 0;
    zep(i, 0, n){
        mx = min(mx, b[i]);
        mn = max(mn, a[i]);
    }

    print(max(mx - mn + 1, 0LL))

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
void init(void)
{
    cin.tie(0) ;
    cin.sync_with_stdio(0) ;
}
int main()
{
    init() ;
    int n , temp ;
    bool flag = true ;
cin >> n;
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] ;
pair<int,int> minmax ;
minmax.first = 0 ;
minmax.second = 10001 ;
for(int i = 0 ;i<n;i++)
{
    if(b[i] >= minmax.first)
    {
        if(a[i]>minmax.first) minmax.first = a[i] ;
        if(b[i]<minmax.second) minmax.second = b[i] ;
    }else
    {
        flag = false ;
        cout<<0 ;
        break;
    }

}
if(flag == true ) cout << minmax.second - minmax.first +1 ;
    return 0;
}