#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < M; i++) cin >> B[i];
  ll ans = 1;
  vector<vector<ll> > dp(N + 1, vector<ll>(M + 1));
  for (int i = 0; i <= M; i++) dp[0][i] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      ll add = (A[i] == B[j] ? dp[i][j] : 0);
      (ans += add) %= MOD;
      dp[i + 1][j + 1] += dp[i + 1][j] + add;
    }
    for (int j = 0; j <= M; j++) {
      dp[i + 1][j] += dp[i][j];
    }
  }
  (ans += MOD) %= MOD;
  cout << ans << endl;
  return 0;
}
