#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2 * 1e3 + 10;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
int N, M, S[MAX], T[MAX];
long long dp[MAX][MAX], sum[MAX][MAX];
int main() {
  cin >> N >> M;
  for (int i = 0; i < (N); ++i) cin >> S[i];
  for (int i = 0; i < (M); ++i) cin >> T[i];
  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (M); ++j) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD;
      } else {
        dp[i + 1][j + 1] = 0;
      }
      sum[i + 1][j + 1] =
          (sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1]) % MOD;
    }
  long long ans = 1;
  for (int i = 0; i < (N + 1); ++i)
    for (int j = 0; j < (M + 1); ++j) ans = (ans + dp[i][j]) % MOD;
  cout << ans << endl;
}
