#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const long long Mod = 1e9 + 7;
long long dp[MAXN][MAXN];
int N, M;
int S[MAXN], T[MAXN];
void solve() {
  for (int i = N - 1; i >= 0; --i) {
    for (int j = M - 1; j >= 0; --j) {
      dp[i][j] += dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1];
      dp[i][j] %= Mod;
      if (S[i] == T[j]) dp[i][j] += dp[i + 1][j + 1] + 1;
      dp[i][j] %= Mod;
    }
  }
  long long ans = (dp[0][0] + 1) % Mod;
  cout << ans << endl;
}
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];
  solve();
  return 0;
}
