#include <bits/stdc++.h>
using namespace std;
long long N, M;
long long S[2005];
long long T[2005];
long long memo[2005][2005];
int main() {
  cin >> N >> M;
  for (long long i = 0; i < (N); ++i) cin >> S[i + 1];
  for (long long i = 0; i < (M); ++i) cin >> T[i + 1];
  for (long long i = 0; i < (N + 1); ++i) memo[i][0] = 1;
  for (long long j = 0; j < (N + 1); ++j) memo[0][j] = 1;
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= M; j++) {
      if (S[i] == T[j]) {
        memo[i][j] = memo[i - 1][j] + memo[i][j - 1];
        memo[i][j] += 1000000007;
        memo[i][j] %= 1000000007;
      } else {
        memo[i][j] = memo[i - 1][j] + memo[i][j - 1] - memo[i - 1][j - 1];
        memo[i][j] += 1000000007;
        memo[i][j] %= 1000000007;
      }
    }
  }
  cout << memo[N][M] << endl;
}
