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