#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long MOD = 1e9 + 7;
long long N, M;
long long S[2001], T[2001];
long long dp[2001][2001];
int main() {
  cin >> N >> M;
  for (long long i = 1; i <= N; i++) cin >> S[i];
  for (long long i = 1; i <= M; i++) cin >> T[i];
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= M; j++) {
      dp[i][j] = (dp[i][j - 1] + (dp[i - 1][j] - dp[i - 1][j - 1])) % MOD;
      if (S[i] == T[j]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MOD;
      }
    }
  }
  cout << dp[N][M] + 1 << endl;
  return 0;
}
