#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, LIM = 2001;
int N, M, S[LIM], T[LIM], sum[LIM][LIM], dp[LIM][LIM], ans = 1;
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> S[i];
  for (int i = 0; i < M; ++i) cin >> T[i];
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD;
      }
      sum[i + 1][j + 1] =
          (sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1] + MOD) %
          MOD;
      ans += dp[i + 1][j + 1];
      ans %= MOD;
    }
  cout << ans << endl;
}
