#include <bits/stdc++.h>
using namespace std;
int main() {
  const long long int MOD = 1e9 + 7;
  long long int N, M;
  cin >> N >> M;
  vector<long long int> v1(N), v2(M);
  for (long long int i = 0; i < (long long int)(N); i++) cin >> v1[i];
  for (long long int i = 0; i < (long long int)(M); i++) cin >> v2[i];
  vector<vector<long long int>> dp(N + 1, vector<long long int>(M + 1, 0LL));
  vector<vector<long long int>> sum(N + 1, vector<long long int>(M + 1, 0LL));
  for (long long int i = 0; i < (long long int)(N); i++) {
    for (long long int j = 0; j < (long long int)(M); j++) {
      if (v1[i] == v2[j]) {
        dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD;
      }
      sum[i + 1][j + 1] =
          (((((sum[i + 1][j] - sum[i][j]) % MOD) + sum[i][j + 1]) % MOD) +
           dp[i + 1][j + 1]) %
          MOD;
    }
  }
  long long int ans = (sum[N][M] + 1) % MOD;
  cout << ans << endl;
  return 0;
}
