#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[2000], T[2000];
int dp[2000 + 1][2000 + 1];
int solve() {
  for (int i = 0; i <= N; ++i) dp[i][0] = 1;
  for (int j = 0; j <= M; ++j) dp[0][j] = 1;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % 1000000007;
      } else {
        dp[i + 1][j + 1] =
            (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % 1000000007;
      }
    }
  return dp[N][M];
}
int main(int argc, char **argv) {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> S[i];
  for (int i = 0; i < M; ++i) cin >> T[i];
  cout << solve() << endl;
}
