#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
unsigned long long dp[2020][2020];
unsigned long long sum[2020][2020];
int main() {
  unsigned long long N, M;
  cin >> N >> M;
  vector<unsigned long long> S(N + 1), T(M + 1);
  for (int i = 0; i < N; ++i) cin >> S[i];
  for (int i = 0; i < M; ++i) cin >> T[i];
  unsigned long long ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      if (S[i] == T[j])
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] + 1;
      else
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      dp[i + 1][j + 1] = dp[i + 1][j + 1] % mod;
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << (dp[N][M] + 1) % mod << endl;
}
