#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)

int main() {
  int n; cin >> n;
  int amax = 0;
  int bmin = 1000;
  
  int tmp;
  REP(i, n) {
    cin >> tmp;
    if (tmp > amax) amax = tmp;
  }
  REP(i, n) {
    cin >> tmp;
    if (tmp < bmin) bmin = tmp;
  }
  
  if (amax > bmin) {
    cout << 0 << endl;
  } else {
    cout << bmin - amax + 1 << endl;
  }
  
  return 0;
}
#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main(){
int n;
cin >> n;
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 m = 0, M = 1001;
for(int i = 0; i < n; i++){
    m = max(m, min(a[i], b[i]));
    M = min(M, max(a[i], b[i]));
  }
if(M >= m) cout << M - m + 1 << endl;
else cout << 0 << endl;

return 0;
}
 