#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template<class T> void chmax(T& a, T b){
    if(a < b){
        a = b;
    }
}
template<class T> void chmin(T& a, T b){
    if(a > b){
        a = b;
    }
}
int main()
{
    int n;
    cin >> n;
    int a[n],b[n];
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];

    int ans = 0;
    for(int x = 0; x <= 1000; x++){
        bool check = true;
        rep(i,n){
            if(!(a[i] <= x && x <= b[i]))check = false;

        }
        if(check)ans++;

    }

    cout << ans << endl;
    return 0;
}
//#include <stdio.h>
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n+5],b[n+5];
    int min=0;
    int max=10000;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(min<a[i]) min=a[i];
    }
    //cout<<min<<"\n";
    for(int i=0; i<n; i++){
        cin>>b[i];
        if(max>b[i]) max=b[i];
    }
    //cout<<max<<"\n";
    if(min>max) cout<<'0'<<"\n";
    else cout<<(max-min)+1<<"\n";
    return 0;
}

