#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int S[2000], T[2000];
  for (int i = 0; i < (N); i++) cin >> S[i];
  for (int i = 0; i < (M); i++) cin >> T[i];
  long long mod = 1e9 + 7;
  long long dp[2001];
  long long dp2[2001] = {};
  for (int i = 0; i < (M + 1); i++) dp[i] = 1;
  for (int i = 1; i <= (N); i++) {
    for (int j = 1; j <= (M); j++) {
      if (S[i - 1] == T[j - 1]) {
        dp2[j] = dp[j];
        dp[j] = dp[j - 1] + dp[j];
      } else {
        dp[j] = dp[j - 1] + dp2[j];
      }
    }
    if (i % 10 == 0)
      for (int j = 1; j <= (M); j++) dp[j] %= mod;
  }
  cout << (dp[M] % mod) << "\n";
  return 0;
}
