#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[2010][2010];
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> s(n + 1);
  for (int i = 0; i < (n); i++) cin >> s[i + 1];
  vector<int> t(m + 1);
  for (int i = 0; i < (m); i++) cin >> t[i + 1];
  for (int i = 0; i < (2010); i++)
    for (int j = 0; j < (2010); j++) dp[i][j] = 0;
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      long long sum = 0;
      for (int k = 0; k < i; ++k) {
        for (int l = 0; l < j; ++l) {
          (sum += dp[k][l]) %= MOD;
        }
      }
      if (s[i] == t[j]) (dp[i][j] = sum + 1) %= MOD;
    }
  }
  long long ans = 0;
  for (int i = 0; i < (n + 1); i++)
    for (int j = 0; j < (m + 1); j++) {
      (ans += dp[i][j]) %= MOD;
    }
  printf("%lld\n", (ans + 1) / 2);
  return 0;
}
