#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
int main() {
  int N, M;
  cin >> N >> M;
  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];
  ll dp[N + 1][M + 1];
  for (int i = 0; i < N + 1; i++) dp[i][0] = 1;
  for (int j = 0; j < M + 1; j++) dp[0][j] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (S[i - 1] == T[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
}
