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