#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>

#define all(v) v.begin(), v.end()
#define endl "\n"

#define MOD 1e9 + 7

int main()
{
    int n, i, j;
    cin >> n;
    int A[n], B[n];
    for (i = 0; i < n; i++)
        cin >> A[i];
    for (i = 0; i < n; i++)
        cin >> B[i];
    vector<int> v;
    int cnt = 0;
    for (i = 1; i <= 1000; i++)
    {
        int c = 0;
        for (j = 0; j < n; j++)
        {
            if (i <= B[j] && i >= A[j])
                c++;
        }
        if (c == n)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}
#include <bits/stdc++.h>
#define setIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979
#define f first
#define s second
#define ar array
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<long long, long long> pll;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
typedef pair<double, double> pdd;
typedef pair<int, string> pis;
int main() { // Ladder: Do 43
    setIO;
    int a; cin >> a;
    int mx = INT_MIN, mn = INT_MAX;
    for (int i = 0; i < a; i++) {
        int x; cin >> x;
        mx = max(mx, x);
    }
    for (int i = 0; i < a; i++) {
        int x; cin >> x;
        mn = min(mn, x);
    }
    if (mn-mx<0) cout << 0;
    else cout << mn-mx+1;
}