#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[2010], T[2010];
long long int dp[2100][2100] = {0};
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];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= M; ++j) {
      if (i > 0 && j > 0 && S[i - 1] == T[j - 1]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
      if (i > 0) dp[i][j] += dp[i - 1][j];
      dp[i][j] %= 1000000007;
      if (j > 0) dp[i][j] += dp[i][j - 1];
      dp[i][j] %= 1000000007;
      if (i > 0 && j > 0) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[N][M] % 1000000007 << endl;
}
