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