#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(0), ios::sync_with_stdio();
  int n, mn = 1001, mx = -1, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    mx = max(mx, x);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    mn = min(mn, x);
  }
  if (mx > mn) cout << "0\n";
  else
    cout << mn - mx + 1 << '\n';
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
 
int main(void){
    int N;
    cin >> N;
    int A[N], B[N];
    vector<int> x;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    rep(i, N){
        if(i==0){
            for(int j=A[i]; j<=B[i]; j++){
                if(A[i]<=j && B[i]>=j) x.push_back(j);
            }
        }else{
            rep(j, x.size()){
                if(x[j]<A[i] || x[j]>B[i]){
                    x.erase(x.begin()+j);
                    j--;
                }
            }
        }
    }
    
    cout << x.size() << endl;

    return 0;
}