#include <bits/stdc++.h>

using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '['; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << ']'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '{' << p.first << ", " << p.second << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &mp) { os << '['; string sep; for (const auto &x : mp) os << sep << x, sep = ", "; return os << ']'; }
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "] =", dbg_out(__VA_ARGS__)
#define show_testcase(k) cerr << "test-case : " << k << endl;
#else
#define show_testcase(...)
#define dbg(...)
#endif

#define int long long
#define mod 1000000007
#define inf 1e18
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)(x).size()
#define sb(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

const string no = "NO";
const string yes = "YES";

void solve()
{
    //cout << fixed << setprecision(10);
    int n; cin >> n;
    int ans = 0;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].ff;
    }
    for (int i = 0; i < n; i++) {
        cin >> v[i].ss;
    }
    for (int num = 0; num <= 1000; num++) {
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (num >= v[i].ff && num <= v[i].ss) {
                cnt++;
            }
        }
        if (cnt == n) {
            ans++;
        }
    }
    cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int tc = 1; tc <= t; tc++) {
        show_testcase(tc);
        solve();
    }
    return 0;
}

#include <iostream>
using namespace std;

int main() {

	int N;
	cin>>N;
	
	int A[N];
	int B[N];

	for(int i=0;i<N;i++)
	{
		cin>>A[i];
	}

	for(int i=0;i<N;i++)
	{
		cin>>B[i];
	}
	
	int x=A[0],y=B[0];
	for(int i=1;i<N;i++)
	{
		if((x < A[i]))
		{
			x =A[i];
		}
		
		if((y > B[i]))
		{
			y =B[i];
		}
	}
	
	if(y >= x)
	{
		cout<<y-x+1<<endl;
	}
	else
	{
		cout<<0<<endl;
	}

	return 0;
}