#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
long long dp[N][N];
long long a[N], b[N];
long long f(long long i, long long j) {
  if (i == -1 || j == -1) return 1;
  long long &ans = dp[i][j];
  if (ans != -1) return ans;
  ans = (f(i - 1, j) + f(i, j - 1) - f(i - 1, j - 1) + 1000000007) % 1000000007;
  if (a[i] == b[j]) ans = (ans + f(i - 1, j - 1)) % 1000000007;
  return ans;
}
void solve() {
  long long n, m, i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < m; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  memset(dp, -1LL, sizeof dp);
  cout << f(n - 1, m - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
