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