#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
int dp[2010][2010] = {0};
void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N + 1);
  vector<int> T(M + 1);
  for (int i = 0; i < (N); i++) {
    cin >> S[i + 1];
  }
  for (int i = 0; i < (M); i++) {
    cin >> T[i + 1];
  }
  dp[0][0] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i > 0) dp[i][j] += dp[i - 1][j];
      if (j > 0) dp[i][j] += dp[i][j - 1];
      if (i > 0 && j > 0 && S[i] != T[j])
        dp[i][j] += 1000000007 - dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << (dp[N][M]) << endl;
}
int main() {
  solve();
  return 0;
}
