#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll IMF = 1LL << 29;
const double PI = 3.14159265358979323846;
ll s[2005];
ll t[2005];
int main() {
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < n; i++) cin >> s[i];
  for (ll j = 0; j < m; j++) cin >> t[j];
  ll cnt = 0;
  for (ll mask = 0; mask < (1 << n); mask++) {
    for (ll mask2 = 0; mask2 < (1 << m); mask2++) {
      ll tmp = 0;
      for (ll i = 0; i < n; i++) {
        if (mask & (1 << i)) {
          tmp += (tmp * 10 + s[i]) % mod;
        }
      }
      ll tmp2 = 0;
      for (ll i = 0; i < m; i++) {
        if (mask2 & (1 << i)) {
          tmp2 += (tmp2 * 10 + t[i]) % mod;
        }
      }
      if (tmp == tmp2) {
        cnt++;
        cnt %= mod;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
