#include <bits/stdc++.h>
using namespace std;
int n, m, f1[100009], f2[100009], fac[100009], mod = 1e9 + 7, inv[100009];
long long fastpower(long long b, long long p) {
  if (p == 0) return 1;
  return p % 2 == 0 ? fastpower((b * b) % mod, p / 2)
                    : (b * fastpower((b * b) % mod, p / 2) % mod) % mod;
}
long long ncr(int x, int y) {
  if (y > x) return 0;
  long long ans = fac[x], b = fastpower(fac[y] * fac[x - y] % mod, mod - 2);
  return ans * b % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  fac[0] = inv[0] = 1;
  for (int i = 1; i <= 1e5; i++) {
    fac[i] = (1LL * i * fac[i - 1]) % mod;
    inv[i] = fastpower(fac[i], mod - 2);
  }
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    f1[x]++;
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    f2[x]++;
  }
  long long ans = 1;
  for (int i = 1; i <= 1e5; i++) {
    long long sum = 0;
    for (int take = 0; take <= min(f1[i], f2[i]); take++) {
      sum += (1LL * ncr(f1[i], take) * ncr(f2[i], take));
      sum %= mod;
    }
    ans = (1LL * ans * sum) % mod;
  }
  cout << (ans - 1 + mod) % mod;
}
