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