#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1e9 + 7;
static const long long INF = 1e18;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;
void pvector(vector<int> A) {
  cout << "[vector]";
  for (int i = 0; i < A.size(); i++) {
    cout << A[i] << " ";
  }
  cout << endl;
}
static const int MAXS = 100001;
static const int MAXN = 2010;
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> S(N), T(M);
  long long dp[MAXN][MAXN] = {0}, sdp[MAXN][MAXN] = {0};
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> T[i];
  }
  dp[0][0] = 1, sdp[1][1] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i == 0 && j == 0) continue;
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1])
        dp[i][j] = sdp[i][j];
      sdp[i + 1][j + 1] =
          (sdp[i + 1][j] + (sdp[i][j + 1] - sdp[i][j]) % MOD) % MOD +
          dp[i][j] % MOD;
      sdp[i + 1][j + 1] %= MOD;
    }
  }
  cout << sdp[N + 1][M + 1] << endl;
}
