#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dp[2100][2100];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<long long> S(N), T(M);
  for (int i = 0; i < N; ++i) cin >> S[i];
  for (int i = 0; i < M; ++i) cin >> T[i];
  for (int i = 0; i <= N; ++i) dp[i][0] = 1;
  for (int i = 0; i <= M; ++i) dp[0][i] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      if (S[i - 1] == T[j - 1]) {
        if (i > 0 && j > 0) dp[i][j] = dp[i - 1][j - 1] * 2LL;
        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) dp[i][j] -= dp[i - 1][j - 1] * 2LL;
      } else {
        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) dp[i][j] -= dp[i - 1][j - 1];
      }
      dp[i][j] %= mod;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
