#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
long long dp[2010][2010] = {};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  long long S[2010], T[2010];
  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 = (0); i < (N + 1); i++) {
    dp[i][0] = 1;
  }
  for (long long i = (0); i < (M + 1); i++) {
    dp[0][i] = 1;
  }
  for (long long i = (0); i < (N); i++) {
    for (long long j = (0); j < (M); j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
      } else {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % MOD;
      }
    }
  }
  cout << (dp[N][M]) << endl;
  ;
}
