#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define MOD2 1000000009
#define MOD3 998244353
#define endl "\n"
#define pii pair <int, int>
#define pll pair <ll, ll>
#define plllll pair <ll, pair<ll, pair<ll, pair<ll, ll>>>>
#define vii std::vector<int>
#define vll std::vector<ll>
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 




int main()
{   
    IOS;
        #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
        #endif

    // int t;
    // cin >> t;
    // while(t--) {
        
        
        
    // }
    int n;
    cin >> n;
    std::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 ans = 0;
    for(int i = 1; i <= 1000; i++) {
        int ok = 1;
        for(int j = 0; j < n; j++) {
            if(i >= a[j] && i <= b[j]) {
                ok = 1;
            }
            else {
                ok = 0;
                break;
            }
        }
        if(ok)
            ans++;
    }
    cout << ans;

return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define int          	long long int
#define pb           	push_back
#define mp           	make_pair
#define all(x)       	x.begin(),x.end()
#define rep(i,a,b)   	for(int i=a;i<b;i++)
#define mem1(a)      	memset (a,-1,sizeof(a))
#define mem0(a)      	memset (a,0,sizeof(a))
#define sz(x)        	(int)((x).size())
#define rr           	return 0
#define f            	first
#define s            	second
#define pii          	pair<int,int>
#define endl         	"\n"
#define bigprime     	1000000007
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        (a/gcd(a,b))*b
#define scanvec(a,n)      rep(i,0,n){cin>>a[i];}
#define printvec(a,n)     rep(i,0,n){cout<<a[i]<<" ";}

//bool ispalindrome(string s){string str = s;reverse(str.begin(),str.end());return(s==str);}
//bool isPrime(int N){for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
//bool isvowel(char x){ ret//longest common subsequence using memoization over recursion
//int fastexpo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
	
void dothis(){
	int n;cin>>n;
	std::vector<int> a(n);
	scanvec(a,n);
	std::vector<int> b(n);
	scanvec(b,n);
	int y = *min_element(all(b));
	int x = *max_element(all(a));
	int zero = 0;
	cout<<max(zero,y-x+1);
}	

signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int t;cin>>t;while(t--){dothis();}
    dothis();
	rr;
}