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