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