#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)1e9 + 7;
long long INF = (long long)2e18;
const long long maxN = 3005;
long long S[maxN], T[maxN];
long long N, M, dp[maxN][maxN];
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < N; i++) cin >> S[i];
  for (long long i = 0; i < M; i++) cin >> T[i];
  for (long long i = 0; i <= N; i++)
    memset(dp[i], 0, sizeof(long long) * (M + 1));
  for (long long i = 1; i <= N; i++) {
    unordered_map<long long, long long> temp;
    for (long long j = 1; j <= M; j++) {
      dp[i][j] = dp[i][j - 1];
      temp[S[i - 1]]++;
      if (S[i - 1] == T[j - 1])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + temp[T[j - 1]]) % mod;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= N; i++) ans = (ans + dp[i][M]) % mod;
  cout << ans << endl;
}
