#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
using namespace std;
long long dp[2050][2050];
long long sdp[2010][2010];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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];
  dp[0][0] = 1;
  sdp[1][1] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      dp[i][j] %= MOD;
      sdp[i][j] %= MOD;
      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] + dp[i][j]) % MOD;
    }
  }
  cout << sdp[N + 1][M + 1] % MOD << endl;
}
