#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

LL powmod(LL x, LL y){
	LL a = 1;
	while(y){
		if(y & 1){ a = a * x % MOD; }
		x = x * x % MOD;
		y >>= 1;
	}
	return a;
}

const int LIM = 1000010;
LL fact[LIM];
LL ifact[LIM];

LL perm(int n, int k){
	if(n < 0 || k < 0 || n < k){ return 0; }
	return fact[n] * ifact[n - k] % MOD;
}

LL solve(){
	const int INF = 1010101010;

	int n, m;
	cin >> n >> m;
	vector<int> as(n + 1, INF), bs(m + 1, INF);
	for(int i = 0; i < n; ++i){ cin >> as[i]; }
	for(int i = 0; i < m; ++i){ cin >> bs[i]; }
	sort(ALL(as));
	sort(ALL(bs));

	for(int i = 1; i < n; ++i){
		if(as[i - 1] == as[i]){ return 0; }
	}
	for(int i = 1; i < m; ++i){
		if(bs[i - 1] == bs[i]){ return 0; }
	}

	int i = 0, j = 0;
	int rems[] = {m, n};
	LL ans = 1;
	int det = 0;
	while(i < n || j < m){
		if(as[i] < bs[j]){
			int v = as[i];
			int k = 0;
			LL t = perm(v - det, rems[k]) - perm(v - det - 1, rems[k]);
			ans = ans * t % MOD;
			det += rems[k];
			--rems[!k];
			++i;
		}
		else if(as[i] > bs[j]){
			int v = bs[j];
			int k = 1;
			LL t = perm(v - det, rems[k]) - perm(v - det - 1, rems[k]);
			ans = ans * t % MOD;
			det += rems[k];
			--rems[!k];
			++j;
		}
		else{
			int v = as[i];
			LL t = perm(v - det - 1, rems[0] + rems[1] - 2);
			ans = ans * t % MOD;
			det += rems[0] + rems[1] - 1;
			--rems[0];
			--rems[1];
			++i;
			++j;
		}
	}

	ans = (ans % MOD + MOD) % MOD;
	return ans;
}

void mainmain(){
	fact[0] = 1;
	for(int i = 1; i < LIM; ++i){
		fact[i] = fact[i - 1] * i % MOD;
	}
	ifact[LIM - 1] = powmod(fact[LIM - 1], MOD - 2);
	for(int i = LIM - 1; i > 0; --i){
		ifact[i - 1] = ifact[i] * i % MOD;
	}
	
	cout << solve() << '\n';
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 15872