#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, vector<long long int>(M, 0LL));
  vector<vector<long long int>> sum(N, vector<long long int>(M, 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]) {
        if (i == 0 || j == 0)
          dp[i][j] = 1;
        else {
          dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
        }
      }
      if (i != 0 && j != 0)
        sum[i][j] =
            (((((sum[i][j - 1] - sum[i - 1][j - 1]) % MOD) + sum[i - 1][j]) %
              MOD) +
             dp[i][j]) %
            MOD;
      else if (i == 0 && j == 0)
        sum[0][0] = dp[i][j];
      else if (i == 0)
        sum[i][j] = (sum[i][j - 1] + dp[i][j]) % MOD;
      else if (j == 0)
        sum[i][j] = (sum[i - 1][j] + dp[i][j]) % MOD;
    }
  }
  cout << ((sum[N - 1][M - 1] + 1) % MOD) << endl;
  return 0;
}
