#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int array1[N], array2[N];
    for(int i = 0; i < N; i++) cin >> array1[i];
    for(int i = 0; i < N; i++) cin >> array2[i];
    int result = 0;
    for(int i = 1; i <= 1000; i++){
        bool check = true;
        for(int j = 0; j < N; j++){
            if(i < array1[j] || i > array2[j]) check = false;
        }
        if(check) result++;
    }
    cout << result << endl;
    //for(int i = 0; i < N; i++) cout << array1[i] << array2[i];
}
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;


int main(){

    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 l = 0, r = 1000;
    for (int i = 0; i < n; ++i){
        l = max(l, a[i]);
        r = min(r, b[i]);
    }
    cout << max(0, r - l + 1);

    return 0;
}

