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