#include <bits/stdc++.h>
using namespace std;
long long MOD = pow(10, 9) + 7;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N), T(M);
  for (long long i(0); i < N; ++i) {
    cin >> S[i];
  }
  for (long long i(0); i < M; ++i) {
    cin >> T[i];
  }
  long long dp[N][M], sum[N + 1][M + 1], ans(1);
  for (long long i(0); i < N + 1; ++i) {
    for (long long j(0); j < M + 1; ++j) {
      if (i == 0 || j == 0) {
        sum[i][j] = 1;
      } else {
        if (S[i - 1] != T[j - 1]) {
          dp[i - 1][j - 1] = 0;
        } else {
          dp[i - 1][j - 1] = sum[i - 1][j - 1] % MOD;
          ans += dp[i - 1][j - 1];
          ans %= MOD;
        }
        sum[i][j] = (sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] +
                     dp[i - 1][j - 1]) %
                    MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
