#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];
  vector<vector<ll>> dp(2020, vector<ll>(2020));
  vector<vector<ll>> sum(2020, vector<ll>(2020));
  dp[0][0] = 1;
  for (int i = 0; i < 2020; i++) sum[i][0] = sum[0][i] = 1;
  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] % MOD;
      sum[i + 1][j + 1] =
          (sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1]) % MOD;
    }
  cout << sum[N][M] << endl;
}
