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

#define ll long long
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define P pair<ll, ll>
#define all(a) (a).begin(), (a).end()

int main(){
    ll n;
    cin >> n;

    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    vector<bool> x(1001, true);
    rep(i, n){
        drep(j, 0, a[i]-1) x[j] = false;
        drep(j, b[i]+1, 1000) x[j] = false;
    }

    ll ans = 0;
    rep(i, x.size()) if(x[i]) ans++;

    cout << ans << endl;
}
#include<string>
#include<iostream>
int main(){
    int N,A[100],B[100],z=1000,w=0;
    std::cin>>N;
    for(int f=0;f<N;f++){
        std::cin>>A[f];
    }
    for(int i=0;i<N;i++){
        std::cin>>B[i];
    }
    for(int t=0;t<N;t++){
       if(z>=B[t])z=B[t];
       if(w<=A[t])w=A[t];
    }
    if(z>=w)std::cout<<z-w+1;
    else std::cout<<0;
    return 0;
}