#include <bits/stdc++.h>
 
int main(){
  int N;
  std::cin>>N;
  int A, B, A_max = 0;
  int B_min = 1000;
  for (int i = 0; i<N; ++i){
    std::cin>>A;
    if(A>A_max)
      A_max = A;
  }
  for (int i = 0; i<N; ++i){
    std::cin>>B;
    if(B<B_min)
      B_min = B;
  }
  int c = 0;
  for (int i = A_max; i<=B_min; i++)
    ++c;
  std::cout<<c<<std::endl;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;


int a[1010], b[1010];
int main() {
  int n;
  cin >> n;

  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];

  int ans = 0;
  for (int i = 1; i <= 1000; i++)
  {
    bool ok = true;
    rep(j,n) {
      if(!(a[j] <= i && i <= b[j])) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
  return 0;
}