#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vp;
typedef set<ll> si;
typedef map<string, ll> msi;
#define REP(i,a,b) \
for(ll i=ll(a);i<=ll(b);i++)
#define DEP(i,a,b) \
for(ll i=ll(a);i>=ll(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
ll mod = 1e9+7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int T;
  T=1;
  while(T--)
  {
      ll n,i,j,k,l,m;
      cin>>n;
      ll x,y;
      ll a[n],b[n];
      REP(i,0,n-1)cin>>a[i];
      REP(i,0,n-1)cin>>b[i];
      x=a[0];
      y=b[0];
      int flag=0;
      REP(i,1,n-1){
        k=a[i];
        m=b[i];
        x=max(k,x);
        y=min(y,m);
        if(x>y)flag=1;
        //cout<<x<<" "<<y<<endl;
      }
      if(flag)cout<<"0";
      else cout<<y-x+1;
  }
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 4000010
#define md 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
/*inline ll add(ll a,ll b){return (a+b)%md;}
inline ll mul(ll a,ll b){return (a*b)%md;}
ll f[M],iv[M];
ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
void prep_fac(){
    f[0]=1;
    rep(i,1,M)f[i]=mul(i,f[i-1]);
    iv[M-1]=power(f[M-1],md-2,md);
    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
}*/


int main()
{
	IOS;
	ll n;
	cin>>n;
	set<ll>s;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ll x=n/i;
			ll y=i;
			s.insert(x);
			s.insert(y);
		}
	}
	for(auto it=s.begin();it!=s.end();it++){
		cout<<*it<<endl;
	}
}

