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