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