#include <bits/stdc++.h>
using namespace std;
long long int containsDigit(long long int number, long long int digit) {
  while (number != 0) {
    int curr_digit = number % 10;
    if (curr_digit == digit) return 1;
    number /= 10;
  }
  return 0;
}
long long int soltn(long long int x, long long int n) {
  if (x >= 0)
    return x % n;
  else
    return n + x % n;
}
long long int pd(long long int x, long long int y) {
  if (x % y == 0)
    return x / y;
  else
    return x / y + 1;
}
long long int coda(long long int n, long long int d) {
  long long int count = 0;
  while (n != 0) {
    if (n % 10 == d) count++;
    n /= 10;
  }
  return count;
}
long long int mdls(long long int x) { return max(x, -x); }
long long int pow1(long long int n, long long int p) {
  if (p == 0) return 1;
  long long int x = pow1(n, p / 2);
  x = (x * x) % 1000000007;
  if (p % 2 == 0)
    return x;
  else
    return (x * n) % 1000000007;
}
long long int k_sum(long long int a[], long long int n, long long int k) {
  long long int r = 0, sum = 0;
  long long int ans = 0;
  for (long long int l = 0; l < n; l++) {
    while (sum < k) {
      if (r == n)
        break;
      else {
        sum += a[r];
        r++;
      }
    }
    if (sum < k) break;
    ans += n - r + 1;
    sum -= a[l];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int t = 1;
  while (t--) {
    long long int n, m, j, k, i;
    cin >> n >> m;
    ;
    map<long long int, long long int> M;
    long long int a[n], b[m];
    long long int ans = 0, c = 0;
    map<long long int, long long int> MM;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      M[a[i]]++;
    }
    for (long long int i = 0; i < m; i++) {
      cin >> b[i];
      MM[b[i]]++;
    }
    sort(a, a + n);
    sort(b, b + m);
    ans = 1;
    for (i = 0; i < n; i++) {
      if (min(M[a[i]], MM[a[i]]) != 0) ans *= pow1(2, min(M[a[i]], MM[a[i]]));
      ans %= 1000000007;
      M[a[i]] = 0;
      MM[a[i]] = 0;
    }
    cout << ans;
    cout << "\n";
  }
  return 0;
}
