#include <bits/stdc++.h>
using namespace std;
const int INF = 1e+9;
const long long INFLL = 1e+17;
const long long MOD = 1e+9 + 7;
int N, M;
int S[2010], T[2010];
long long dp[2010][2010];
long long sum[2010][2010];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];
  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      dp[i][j] = (S[i - 1] == T[j - 1] ? (sum[i - 1][j - 1] + 1) % MOD : 0);
      sum[i][j] =
          (dp[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]) % MOD;
    }
  }
  long long res = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      res = (res + dp[i][j]) % MOD;
    }
  }
  res = (res + 1) % MOD;
  cout << res << "\n";
  return 0;
}
