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