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