#include <bits/stdc++.h>
void solve();
int main() {
  solve();
  return 0;
}
using namespace std;
int N, M;
vector<int> S, T;
int MOD = 1e9 + 7;
vector<vector<long long>> dp;
vector<vector<long long>> p;
void solve() {
  cin >> N >> M;
  S.resize(N + 1);
  T.resize(M + 1);
  for (int n = 1; n <= N; n++) cin >> S[n];
  for (int m = 1; m <= M; m++) cin >> T[m];
  dp.resize(N + 1);
  p.resize(N + 1);
  for (int n = 0; n <= N; n++) {
    dp[n].resize(M + 1, 0);
    p[n].resize(M + 1, 0);
  }
  for (int s = 1; s <= N; s++) {
    for (int t = 1; t <= M; t++) {
      if (S[s] == T[t]) {
        dp[s][t] = p[s - 1][t - 1] + 1;
        dp[s][t] %= MOD;
      }
      p[s][t] = p[s][t - 1] + p[s - 1][t] - p[s - 1][t - 1] + dp[s][t];
      p[s][t] %= MOD;
    }
  }
  cout << (p[N][M] + 1) % MOD << endl;
  return;
}
