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

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;

    vector<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];
    }

    int left = INT_MIN;
    int right = INT_MAX;


    for(int i = 0;i<n;++i){
        left = max(left,a[i]);
        right = min(right,b[i]);
    }
    cout<< max(0,right-left+1);

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

int main()
{
    int nem[1000]={0};
    int N;
    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];
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <1000; j++)
        {
            if (j < a[i]-1)
            {
                nem[j]++;
            }

            if (j > b[i] - 1)
            {
                nem[j]++;
            }
            else continue;
        }
    }

    int counter = 0;
    for (int k = 0; k < 1000; k++)
    {
        if (nem[k] == 0)
        {
            counter++;
        }
    }


        cout << counter << endl;
}

