#include <bits/stdc++.h>
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::fill;
using std::ios_base;
using std::iterator;
using std::lower_bound;
using std::map;
using std::max_element;
using std::min_element;
using std::multimap;
using std::multiset;
using std::next_permutation;
using std::pair;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::stable_sort;
using std::stack;
using std::string;
using std::swap;
using std::unique;
using std::vector;
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long min(long long a, long long b) {
  if (a > b) return b;
  return a;
}
namespace MySpace {};
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long n, m;
long long s[50000];
long long t[50000];
long long cntS[150000];
long long cntT[150000];
long long cnk[2100][2100];
long long dp[150000];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
    cntS[s[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    cin >> t[i];
    cntT[t[i]]++;
  }
  for (long long i = 0; i <= 2000; i++) {
    for (long long j = 0; j <= i; j++) {
      if (j == 0 || j - i == 0)
        cnk[i][j] = 1;
      else
        cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % MOD;
    }
  }
  dp[0] = 1;
  for (long long i = 1; i <= 140000; i++) {
    for (long long j = 0; j <= min(cntS[i], cntT[i]); j++) {
      dp[i] += dp[i - 1] * cnk[cntS[i]][j] % MOD * cnk[cntT[i]][j] % MOD;
      dp[i] %= MOD;
    }
  }
  cout << dp[140000];
}
