#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> S(N), T(M);
  for (int64_t i = 0; i < N; i++) cin >> S[i];
  for (int64_t i = 0; i < M; i++) cin >> T[i];
  vector<vector<int64_t>> dp(N + 1, vector<int64_t>(M + 1, 0)),
      sdp(N + 2, vector<int64_t>(M + 2, 0));
  dp[0][0] = 1;
  for (int64_t i = 0; i < N + 1; i++) {
    for (int64_t j = 0; j < M + 1; j++) {
      if (i - 1 >= 0 && j - 1 >= 0 & S[i - 1] == T[j - 1]) dp[i][j] = sdp[i][j];
      sdp[i + 1][j + 1] =
          (sdp[i + 1][j] + sdp[i][j + 1] + dp[i][j] - sdp[i][j]) % MOD;
    }
  }
  cout << sdp[N + 1][M + 1] << "\n";
}
