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