#include <bits/stdc++.h>
using namespace std;
long long INFl = 1e+18 + 1;
int INF = 1e+9 + 1;
long long dp[2001][2001];
long long MOD = 1e+9 + 7;
int main() {
  int N, M;
  int S[10001], T[10001];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  for (int x = 1; x <= N; x++) {
    for (int y = 1; y <= M; y++) {
      if (S[x - 1] == T[y - 1]) {
        dp[x][y] = dp[x - 1][y - 1] + 1;
      } else
        dp[x][y] = 0;
      dp[x][y] += (dp[x - 1][y] + dp[x][y - 1] - dp[x - 1][y - 1] + MOD) % MOD;
      dp[x][y] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
