#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long dp[2050][2050] = {};
int main() {
  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];
  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 - 1][j - 1] + 1;
        dp[i][j] %= MOD;
      }
      dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << (dp[N][M] + 1) % MOD << endl;
}
