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