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