#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  int 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];
  long long int dp[N + 1][M + 1];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      dp[i][j] = 0;
    }
  }
  long long int MOD = 1000000007;
  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) % MOD;
      dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % MOD;
    }
  }
  cout << dp[N][M] + 1 << endl;
}
