#include <bits/stdc++.h>
using namespace std;
long long dp[2010][2010];
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  long long S[2010], T[2010];
  for (long long i = 0; i < N; i++) cin >> S[i];
  for (long long i = 0; i < M; i++) cin >> T[i];
  dp[0][0] = 1;
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) {
      if (S[i] == T[j])
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % 1000000007;
      dp[i + 1][j + 1] =
          (dp[i + 1][j + 1] + dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) %
          1000000007;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
