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

int read();
#define LL long long
#define fr(i,l,r) for(int i = (l);i <= (r);++i)
#define rf(i,l,r) for(int i = (l);i >= (r);--i)
#define fo(i,l,r) for(int i = (l);i < (r);++i)
#define foredge(i,u,v) for(int i = fir[u],v;v = to[i],i;i = nxt[i])
#define ci const int &
#define cl const LL &
#define I inline void
#define filein(File) freopen(File".in","r",stdin)
#define fileout(File) freopen(File".out","w",stdout)

const int N = 1e5 + 5,MOD = 1e9 + 7;
int n,a[N];
LL ans = 1;
int main() {
	cin >> n;
	fr(i,1,n) cin >> a[i];
	sort(a+1,a+n+1);
	fr(i,1,n) ans = ans * (a[i]-a[i-1]+1) % MOD;
	cout << ans << endl;
	return 0;
}

const int S = 1 << 21;
char p0[S],*p1,*p2;
#define getchar() (p2 == p1 && (p2 = (p1 = p0) + fread(p0,1,S,stdin)) == p1 ? EOF : *p1++)
inline int read() {
	static int x,c,f;x = 0;f = 1;
	do c = getchar(),c == '-' && (f = -1);while(!isdigit(c));
	do x = x * 10 + (c & 15),c = getchar();while(isdigit(c));
	return x * f;
}

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

const ll INF = 10000000000009;

int main()
{
    int n, m;
    cin >> n >> m;
    ll h[200005], w[200005];
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < m; i++) cin >> w[i];
    sort(h, h + n);
    sort(w, w + m);
    ll t[200005];
    for(int i = 0; i < n; i++){
        int j = lower_bound(w, w + m, h[i]) - w;
        t[i] = INF;
        if(j < m) t[i] = w[j] - h[i];
        if(j > 0) t[i] = min(t[i], h[i] - w[j - 1]);
    }
    ll l[200005], r[200005];
    l[1] = h[1] - h[0];
    for(int i = 3; i < n; i += 2) l[i] = l[i - 2] + (h[i] - h[i - 1]);
    r[n - 2] = h[n - 1] - h[n - 2];
    for(int i = n - 4; i >= 0; i -= 2) r[i] = r[i + 2] + (h[i + 1] - h[i]);
    ll ans = INF;
    for(int i = 0; i < n; i++){
        if(i % 2){
            ll s = t[i] + (h[i + 1] - h[i - 1]);
            if(i > 1) s += l[i - 2];
            if(i < n - 2) s += r[i + 2];
            ans = min(ans, s);
        }
        else{
            ll s = t[i];
            if(i > 0) s += l[i - 1];
            if(i < n - 1) s += r[i + 1];
            ans = min(ans, s);
        }
    }
    cout << ans << endl;
}
