#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
const int mod = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int i = 0; i < (int)(N); ++i) cin >> S[i];
  for (int i = 0; i < (int)(M); ++i) cin >> T[i];
  vector<vector<int>> dp(N + 1, vector<int>(M + 1, 1));
  for (int i = 0; i < (int)(N); ++i)
    for (int j = 0; j < (int)(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] << "\n";
  return 0;
}
