#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  long long inf = 1000000007;
  cin >> N >> M;
  long long dp[2][M + 100];
  long long S[N + 10];
  long long T[M + 10];
  long long s, t;
  dp[0][0] = 1;
  dp[1][0] = 1;
  for (int i = 1; i <= N; ++i) {
    cin >> s;
    S[i] = s;
  }
  for (int j = 1; j <= M; ++j) {
    cin >> t;
    T[j] = t;
    dp[0][j] = 1;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      if (S[i] == T[j]) {
        dp[1][j] = (dp[0][j] + dp[1][j - 1]) % inf;
      } else {
        dp[1][j] = (dp[1][j - 1] + dp[0][j] - dp[0][j - 1]) % inf;
      }
    }
    for (int y = 1; y <= M; ++y) {
      dp[0][y] = dp[1][y];
    }
  }
  long long ans = 0;
  ans = dp[1][M];
  cout << ans << "\n";
  return 0;
}
