#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 5000 + 5;
long long n, m, a[N], b[N], dp[N][N][2];
long long solve(long long x, long long y, long long op) {
  if (x == n || y == m) {
    if (op) {
      if (a[x] == b[y])
        return 2;
      else
        return 1;
    } else {
      if (a[x] == b[y])
        return 1;
      else
        return 0;
    }
  }
  if (dp[x][y][op]) return dp[x][y][op];
  if (x == y)
    dp[x][y][op] =
        dp[x][y][op] + solve(x + 1, y + 1, 1) + solve(x + 1, y + 1, op);
  dp[x][y][op] = dp[x][y][op] + solve(x + 1, y, op) + solve(x, y + 1, op) % mod;
  return dp[x][y][op] % mod;
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= m; i++) scanf("%d", &b[i]);
  sort(b + 1, b + m + 1);
  cout << solve(1, 1, 0) + 1;
}
