#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  long long N, M;
  const long long MEM = 201;
  long long S[MEM], T[MEM];
  long long dp[MEM][MEM] = {};
  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];
  }
  dp[0][0] = 1;
  for (long long i = 0; i < (N + 1); ++i) {
    for (long long j = 0; j < (M + 1); ++j) {
      if (i > 0) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % 1000000007;
      if (j > 0) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % 1000000007;
      if (i > 0 && j > 0 && S[i - 1] != T[j - 1])
        dp[i][j] = (dp[i][j] - dp[i - 1][j - 1] + 1000000007) % 1000000007;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
