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