#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define input(v) for (auto &i : v) cin >> i;
#define print(v) for (auto &j : v) cout << j << " "; cout << "\n";

void solve()
{
    int n;
    cin>>n;
    vector<int>a(n),b(n);input(a);input(b);
    int mx = max(a[0],b[0]);
    int mn = min(a[0],b[0]);
    for(int i=0;i<n;i++)
    {
        mx=min(mx,max(a[i],b[i]));
        mn=max(mn,min(a[i],b[i]));
    }
    if(mx-mn+1<0)
    {
        cout<<"0\n";
        return;
    }
    cout<<mx-mn+1<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int testcases=1;
    //cin>>testcases;
    while(testcases--) solve();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define quickread                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define hii cout << "Hii there Sparky! \n"
#define endl '\n'
#define mod 1000000007
//#define mod 998244353
#define maxn 100010 //check the limits, dummy

void solve() {
    int n;
    cin >> n;
    int arr[n];
    int mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        mx = max(arr[i], mx);
    }
    int arr2[n];
    int mn = INT_MAX;
    for (int i = 0; i < n; i++) {
        cin >> arr2[i];
        mn = min(arr2[i], mn);
    }
    cout << max(0LL, mn - mx + 1);
}

int32_t main() {
    quickread;
    int test = 1;
    //cin >> test;
    for (int i = 0; i < test; i++) {
        solve();
    }
    return 0;
}