#include <bits/stdc++.h>
using namespace std;
void Enum(vector<long long> const& arr, int i, string const& work,
          map<string, long long>* dst) {
  if (i >= arr.size()) {
    (*dst)[work] += 1;
    return;
  }
  Enum(arr, i + 1, work, dst);
  string nextWork = work + "_" + std::to_string(arr[i]);
  Enum(arr, i + 1, nextWork, dst);
}
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N);
  vector<long long> T(M);
  for (long long i = 0; i < (N); ++i) {
    cin >> S[i];
  }
  for (long long i = 0; i < (M); ++i) {
    cin >> T[i];
  }
  map<string, long long> s_map;
  map<string, long long> t_map;
  Enum(S, 0, "", &s_map);
  Enum(T, 0, "", &t_map);
  long long cnt = 0;
  for (auto const& p : s_map) {
    auto const& key = p.first;
    cnt += p.second * t_map[key];
    cnt %= 1000000007;
  }
  cout << cnt << endl;
  return 0;
}
