#include <bits/stdc++.h>
using namespace std;
long long N, M, MAX = 2001;
vector<long long> S(MAX), T(MAX);
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < N; i++) cin >> S[i];
  for (long long i = 0; i < M; i++) cin >> T[i];
  vector<vector<long long>> s, t;
  for (long long bit = 0; bit < (1 << N); bit++) {
    vector<long long> U;
    for (long long i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        U.push_back(S[i]);
      }
    }
    s.push_back(U);
  }
  for (long long bit = 0; bit < (1 << M); bit++) {
    vector<long long> U;
    for (long long i = 0; i < M; i++) {
      if (bit & (1 << i)) {
        U.push_back(T[i]);
      }
    }
    t.push_back(U);
  }
  long long ans = 0;
  for (long long i = 0; i < s.size(); i++) {
    for (long long j = 0; j < t.size(); j++) {
      if (s[i] == t[j]) ans++;
      if (ans > 1000000007) ans = ans % 1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
