#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[2010][2010];
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> S(N);
  vector<long long> T(M);
  for (long long i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (long long j = 0; j < M; j++) {
    cin >> T[j];
  }
  for (long long i = 0; i < 2010; i++) {
    for (long long j = 0; j < 2010; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (long long i = 0; i <= N; i++) {
    for (long long j = 0; j <= M; j++) {
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1];
      } else if (i - 1 >= 0) {
        dp[i][j] += dp[i - 1][j];
      } else if (j - 1 >= 0) {
        dp[i][j] += dp[i][j - 1];
      }
      if (i - 1 >= 0 && j - 1 >= 0) {
        dp[i][j] -= dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
