#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int main() {
  long long mod = 1e9 + 7;
  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];
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1, 1));
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j) {
      if (S[i - 1] == T[j - 1])
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
      else
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mod) % mod;
    }
  cerr << "debug" << endl;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= M; ++j) {
      cerr << dp[i][j] << " ";
    }
    cerr << endl;
  }
  cout << dp[N][M] << endl;
  return 0;
}
