var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
var mod = 1e9+7;
function lower_bound(d,a,b,e){for(var c;1<b-a;)d[c=0|(a+b)/2]<e?a=c:b=c;return d[a]<e?b:a};
function abmod(){for(var a=arguments,r=a[0],i=1;i<a.length;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i++])%mod;return r;}
var fact=[1,1];
function factmod(n){for(var i=fact.length;i<=n;)fact[i]=abmod(fact[i-1],i++);return fact[n];}
function modinv(a){for(var b=mod,u=1,v=0,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function nPrmod(n,r){return abmod(factmod(n),modinv(fact[n-r]));}

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = o.l();
  var b = o.l();
  if(Array.from(new Set(a)).length !== a.length)return 0;
  if(Array.from(new Set(b)).length !== b.length)return 0;
  a.sort((a,b)=>a-b);
  b.sort((a,b)=>a-b);
  var ans = 1;
  var x = 0, y = 0, k = 1;
  while(x < n && y < m){
    var t;
    if(a[x] < b[y]){
      t = m - y;
      ans = abmod(ans, t, nPrmod(a[x]-k, t-1));
      x++;
    }else if(a[x] === b[y]){
      t = m - y + n - x - 1;
      ans = abmod(ans, nPrmod(a[x]-k, t-1));
      x++, y++;
    }else{
      t = n - x;
      ans = abmod(ans, t, nPrmod(b[y]-k, t-1));
      y++;
    }
    k += t;
  }
  return ans;
}