#include <bits/stdc++.h>
using namespace std;
long long dp[2001][2001];
int S[2000];
int T[2000];
long long divi = 1000000000 + 7;
int main() {
  int N, M;
  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 i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1) % divi;
      } else {
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % divi;
      }
    }
  }
  cout << (dp[N][M] + 1) % divi << "\n";
}
