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