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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n; cin >> n;
    vector<int> a(n), b(n);
    cin >> a >> b;

    cout << max(0, *min_element(b.begin(), b.end()) - *max_element(a.begin(), a.end()) + 1) << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T>
void print(T a, string message = "debug: ");
template <typename T>
void printvec(vector<T> a, string message = "debug: ");
int n;
vector<int> a, b;

int main()
{
  cin >> n;
  a.resize(n);
  b.resize(n);
  int amin = 0, bmax = 1000;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    if (amin < a[i])
    {
      amin = a[i];
    }
  }
  for (int i = 0; i < n; i++)
  {
    cin >> b[i];
    if (bmax > b[i])
    {
      bmax = b[i];
    }
  }

  if (bmax - amin + 1 > 0){
    cout << bmax - amin + 1 << endl;
  }else{
    cout << 0 << endl;
  }

  return 0;
}

template <typename T>
void print(T a, string message)
{
  cout << message << a << endl;
}
template <typename T>
void printvec(vector<T> a, string message)
{
  for (ll i = 0; i < a.size(); i++)
  {
    cout << message << "[" << i << "]: " << a[i] << endl;
  }
}