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