#include <bits/stdc++.h>
using namespace std;
constexpr long long int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }
const int max_n = 3000;
long long int dp[max_n][max_n];
long long int S[max_n];
long long int T[max_n];
int main(void) {
  int N, M;
  cin >> N >> M;
  dp[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    dp[0][i] = 1;
    cin >> S[i];
  }
  for (int i = 1; i <= M; i++) {
    dp[i][0] = 1;
    cin >> T[i];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (S[i] == T[j]) {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % (1000000007);
      } else {
        dp[i][j] =
            ((1000000007) + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) %
            (1000000007);
      }
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
