#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N + 1), T(M + 1);
  for (long long(i) = 0; (i) < (N); ++i) cin >> S[i + 1];
  for (long long(i) = 0; (i) < (M); ++i) cin >> T[i + 1];
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1));
  vector<vector<long long>> sum(N + 1, vector<long long>(M + 1));
  for (long long i = 1; i < N + 1; i++) {
    for (long long j = 1; j < M + 1; j++) {
      if (S[i] != T[j])
        dp[i][j] = 0;
      else
        dp[i][j] = sum[i - 1][j - 1] + 1;
      sum[i][j] = dp[i][j] + sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
      sum[i][j] %= MOD;
    }
  }
  cout << sum[N][M] + 1 << endl;
  return 0;
}
