#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, m;
long long N, M, K, X;
long long W, H, x, y;
long long ans;
long long dp[2001][2001];
long long S[2003], T[2003];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (long long i = 0; i < (long long)(N); ++i) cin >> S[i];
  for (long long i = 0; i < (long long)(M); ++i) cin >> T[i];
  for (long long i = 0; i < (long long)(N + 1); ++i) dp[i][0] = 1;
  for (long long i = 0; i < (long long)(M + 1); ++i) dp[0][i] = 1;
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= M; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % 1000000007;
      if (S[i - 1] == T[j - 1])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % 1000000007;
    }
  }
  ans = (dp[N][M] % 1000000007);
  cout << ans << endl;
  return 0;
}
