// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}

void main() {
    int n;
    R(n);
    VI a(n),b(n);
    REP(i,n) R(a[i]);
    REP(i,n) R(b[i]);
    int l=0,r=1000;
    REP(i,n) {
        chmax(l,a[i]);
        chmin(r,b[i]);
    }
    int ans=max(0,r-l+1);
    W(ans);
}

 // {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}

#include "bits/stdc++.h"

#define int long long

using namespace std;
using i128 = __int128_t;

random_device rd;
mt19937 gen(rd());

#define random_shuffle(begin, end) shuffle(begin, end, gen)

template <typename T, typename U>
ostream& operator << (ostream& out, const pair <T, U> &p) {
    out << p.first << ": " << p.second;
    return out;
}

template <typename Container>
ostream& print_container(ostream& out, const Container &container, const string &open, const string &close, const string sep=", ") {
    out << open;
    for (const auto &elem : container)
        out << elem << sep;
    out << "\b\b" << close << endl;
    return out;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &v) {
    return print_container(out, v, "[", "]");
}

template <typename T>
ostream& operator << (ostream& out, const set<T> &s) {
    return print_container(out, s, "{", "}");
}

template <typename T>
ostream& operator << (ostream& out, const unordered_set<T> &s) {
    return print_container(out, s, "{", "}");
}

template <typename K, typename V>
ostream& operator << (ostream& out, const map<K, V> &s) {
    return print_container(out, s, "{", "}");
}

template <typename K, typename V>
ostream& operator << (ostream& out, const unordered_map<K, V> &s) {
    return print_container(out, s, "{", "}");
}

template<typename... Args>
void writeln(Args... args) {
    ((cout << args << " "), ...);
    cout << endl;
}

namespace std {
    template <typename T, typename U> struct hash<pair <T, U> > { 
        size_t operator()(const pair <T, U> &p) const {
            hash<int> hasher;
            size_t seed = 0;
            seed ^= hasher(p.first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
            seed ^= hasher(p.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
            return seed;
        }
    };  
}

// End of template

int32_t main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL_JUDGE
    if (freopen("input.txt", "r", stdin) == NULL) {
        cerr << "Couldn't open file for reading" << endl;
        return 0;
    }
#endif
	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 ma = a[0], mi = b[0];
    for (int i = 0; i < n; ++i) {
        ma = max(ma, a[i]);
        mi = min(mi, b[i]);
    }
    cout << max(0LL, mi - ma + 1) << endl;
}