#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;

#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define iint int
#define f(i,a,b)        for(ll i=a;i<b;i++)
#define f0(i,n)         f(i,0,n)
#define fr(i,a,b)       for(ll i=a;i>=b;i--)
#define for1(i,n)       for(ll i=1;i<=n;i++)
#define pb              push_back
#define tc(t)           int t;cin >>t;while(t--)
#define lol             std::ios::sync_with_stdio(false); cin.tie(NULL);
#define endl            "\n"
#define ss              second
#define ff              first
#define ll              long long
#define lld             long double
#define int             long long
#define pii             pair< int,int >
#define pll             pair< ll,ll >
#define sz(a)           a.size()
#define inf             (1000*1000*1000+5)
#define all(a)          a.begin(),a.end()
#define arr(a,n)        int a[n];f0(i, n) cin >> a[i];
#define ini(a,n)        memset(a,n,sizeof(a))
#define printArr(a,n)   f0(i,n) cout<<a[i]<<" ";
#define in              cin>>
#define rr              return 0;
#define vi              vector< int >
#define vs              vector<string>
#define l_b             lower_bound
#define u_b             upper_bound
#define mod             1000000007
#define pi              3.141592653589793238
#define fmap(m)         for(auto it:m)
#define deb(args...)    { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define debarr(arr,a,b) for(int i=(a);i<(b);i++) cout<<(arr[i])<<" ";cout<<endl;
#define long_max        numeric_limits<ll>::max()

vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;}



void remove_dup(vi &a)
{
    auto it = unique(a.begin(), a.end());
    a.resize(distance(a.begin(), it));
}

int dx[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int dy[8] = { +1, 0, -1, +1, -1, +1, 0, -1};

int dx4[4] = { +1 , -1 , +0 , +0};
int dy4[4] = { 0  , 0 , +1 , -1};

const int N = 5e5 + 10;

const int m = 998244353;


int power(int a, int b) //a^b korte hobe   (binary exponentiation)
{
    int result = 1;
    while (b)
    {
        if (b & 1)
        {
            result = (a % m * result % m) % m;
            b--;
        }
        else
        {
            a = (a % m * a % m) % m;
            b >>= 1;
        }
    }
    return result % m;
}


int pow_inverse(int n)
{
    return power(n, m - 2) % m;
}

bool digit(int n)
{
    string s = to_string(n);
    return s.size();
}

void solve()
{
    int n;
    cin >> n;
    arr(a, n);
    arr(b, n);
    int l = min(a[0], b[0]);
    int r = max(a[0], b[0]);
    f(i, 1, n)
    {
        l = max({l , a[i]});
        r = min({r , b[i]});
    }
    if (l <= r)
        cout << r - l + 1 << "\n";
    else
        cout << "0\n";
}

signed main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    lol;


    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
 int n;cin>>n;
 vector<int> a(n);
 for (int i = 0; i < n; i++)cin>>a[i];
int mx = -1;
int ans = 0;
   for (int j = 2; j < 100000; j++)
 {
   int count = 0;
 for (int i = 0; i < n; i++)
   {

     if(a[i]%j == 0)count++;
   }
   mx = max(mx,count);
   if(mx == count)ans = j;
 }
 cout<<ans<<endl;
  
  return 0;
}