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

const ll mod = 1e9 + 7;

int run_test(){
  int n;
  cin >> n;
  int maxi = 0, mini = mod;
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    maxi = max(maxi, k);
  }
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    mini = min(mini, k);
  }
  cout << max(0, mini-maxi+1);
  return 0;
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int tt;
  tt = 1;
  while(tt--){
    run_test();
  }
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for (ll i = 0; i < n; i++)
#define revf(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define rep1(i, b) for (ll i = 1; i <= b; i++)
#define inp(a, n)              \
	for (ll i = 0; i < n; i++) \
	cin >> a[i]
#define outp(a, n)             \
	for (ll i = 0; i < n; i++) \
	cout << a[i] << " "
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (((a) * (b)) / gcd((a), (b)))
#define pb push_back
#define mp make_pair
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define mem(x, n) memset(x, n, sizeof(x))
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define test  \
	ll t;     \
	cin >> t; \
	while (t--)
#define cn cout << "\n";
int main()
{
  fast  
  ll n;
  cin>>n;
  ll ar[n],br[n];
  inp(ar,n);
  inp(br,n);
  set<ll>s;
  for(ll i=1;i<=1000;i++)
  s.insert(i);
  ll q=0;
  REP(i,1,1001)
  {
       forr(j,n)
       {
            if(ar[j]<=i&&i<=br[j])
            q=1;
            else
            s.erase(i);
       }
  }
  cout<<s.size();
}