#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test() int t; cin>>t; while(t--)
#define all(v) v.begin(),v.end()
#define st(v) sort(all(v))
#define stA(arr,n) sort(arr,arr+n)
#define findInVec(v,key) (find(all(v),key)!=v.end())
#define findInSet(v,key) (v.find(key) != v.end())
#define findInStr(s,key) (s.find(key) != string::npos)
#define findInMap(m,key) (mp.find(key) != mp.end())
#define prt(i) cout<<i<<"\n"
#define fos(v) for(auto x:v)
#define fo(m,n,i) for(int i=m;i<n;i++)
#define Fo(m,n,i) for(int i=m;i>n;i--)
#define setbit(i) __builtin_popcount(i)
#define del(v,pos) v.erase(v.begin()+pos)
#define cnt(v,key) (count(all(v),key))
#define cnts(s,key) (s.count(key))
#define sumArr(a,s,e,sum)(accumulate(a+s,a+e,sum))
typedef long long ll;
using namespace std;
ll stringToLong(string s){stringstream raaz(s);ll x = 0;raaz >> x;return x;}
string longToString(ll k){stringstream ss;ss<<k;string s; ss>>s; return s;}
bool isPowerOfTwo(int n){if(n==0) return false; return (ceil(log2(n)) == floor(log2(n)));}
void scanArr(int *arr,int n){fo(0,n,i) cin>>arr[i];}
void printArr(int *arr,int n){fo(0,n,i) cout<<arr[i]<<" ";}
void scanVector(vector<ll> &v,int n){fo(0,n,i){int temp;cin>>temp;v.push_back(temp);}}
void printVector(vector<ll> v){fos(v) cout<<x<<" ";}
int main()
{
	IOS
    int n;
    cin>>n;
    vector<int>a,b;
    int mn=INT_MAX,mx=INT_MAX;
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        a.push_back(k);
    }
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        b.push_back(k);
    }
    int r=b[0],l=a[0];
    for (int i = 1; i < n; i++) {
        if (a[i] > r || b[i] < l) {
            cout <<"0";
            return 0;
        }
        else {
            l = max(l, a[i]);
            r = min(r, b[i]);
        }
    }
    cout<<(r-l)+1;
    return 0;
}

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

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define LL long long
#define ULL unsigned long long
#define LB lower_bound
#define MOD1 1000000007
#define MOD2 1000000009
#define int LL
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
const int maxn = 1e5 + 1;

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(auto &i: a) cin >> i;
  for(auto &i: b) cin >> i;
  if(n == 0){
      cout << 0;
      return;
  }

  int ll = a[0], ul = b[0];

  for(int i = 1; i < n; i++){
      if(a[i] > ll) ll = a[i]; 
      if(b[i] < ul) ul = b[i]; 
  }
	int zero = 0;
    int ans = max(zero,ul-ll+1);
    cout << ans;

}

signed main()
{
    static const int _ = []() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        return 0;
    }();
    int t = 1;
    // cin >> t;

    while (t--)
    {
        solve();
    }
    return 0;
}