#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,i,a=0,b=1001,t;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> t;
    if(t>a) a=t;
  }
  for(i=0;i<n;i++){
    cin >> t;
    if(t<b) b=t;
  }
  cout << max(b-a+1,0) << endl;
  return 0;
}
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0) 
#define sz(a) (a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;
 
const ll N = 1e5 + 100;
const ll M = 3e5 + 101;
const ll big = 1e17;
const ll hsh2 = 1964325029 ;
const long long mod = 1e9 + 7;
const long double EPS = 1e-10;
const ll block = 1e7;
const ll shift = 2e3;
const ld pi = acos(-1.0);

ll n, a[N];
vector<ll> z;
int main() {
	speed;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i], z.pb(a[i]);
	sort(a + 1, a + n + 1);
	ll ans = 1, lst = 0;
	for(int i = 1; i <= n; i++) {
		ans = (ans * ( a[i] - lst + 1)) % mod;
		lst = a[i];
	}
	cout << ans << '\n';
	
}

/*
*/