#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 + 1, vector<long long>(M + 1, 0));
  for (int i = 0; i < (int)(N + 1); i++) dp[i][0] = 1;
  for (int i = 0; i < (int)(M + 1); i++) dp[0][i] = 1;
  for (int i = 0; i < (int)(N); i++) {
    for (int j = 0; j < (int)(M); j++) {
      dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
      if (S[i] != T[j]) dp[i + 1][j + 1] = (dp[i + 1][j + 1] - dp[i][j]) % MOD;
    }
  }
  cout << dp[N][M] << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> S(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
  }
  std::vector<long long> T(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &T[i]);
  }
  solve(N, M, std::move(S), std::move(T));
  return 0;
}
