#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N), B(M);
  for (long long i = (long long)(0); i < (long long)(N); i++) cin >> A[i];
  for (long long i = (long long)(0); i < (long long)(M); i++) cin >> B[i];
  vector<vector<long long> > dp(N + 1, vector<long long>(M + 1, 1));
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    for (long long j = (long long)(0); j < (long long)(M); j++) {
      dp[i + 1][j + 1] = dp[i + 1][j];
      if (A[i] == B[i]) dp[i + 1][j + 1] += dp[i][j] + 1;
      dp[i + 1][j + 1] %= 1000000007;
    }
  }
  cout << dp[N][M] << endl;
}
