#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MOD = 1e9 + 7;

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);

  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];

  static int dp[2020][2020];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < 2020; i++) dp[i][0] = dp[0][i] = 1;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD;
      if (S[i] != T[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] - dp[i][j] + MOD) % MOD;
      }
    }
  }

  cout << dp[N][M] << endl;
  return 0;
}
