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