#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
void solve(long long N, long long M, std::vector<long long> S,
           std::vector<long long> T) {
  vector<vector<long long>> dp(N, vector<long long>(M));
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) {
      long long top = (i > 0) ? dp[i - 1][j] : 0;
      long long side = (j > 0) ? dp[i][j - 1] : 0;
      long long diag = (i > 0 and j > 0) ? dp[i - 1][j - 1] : 0;
      long long res = top + side - diag;
      if (S[i] == T[j]) {
        res += 1 + diag;
      }
      dp[i][j] = res % MOD;
    }
  }
  cout << dp.back().back() + 1 << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> S(N);
  for (long long i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
  }
  std::vector<long long> T(M);
  for (long long i = 0; i < M; i++) {
    scanf("%lld", &T[i]);
  }
  solve(N, M, std::move(S), std::move(T));
  return 0;
}
