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