#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long MOD = 1000000007;
  int N, M;
  cin >> N >> M;
  vector<long long> s(N);
  vector<long long> t(M);
  for (int i = 0; i < N; i++) cin >> s[i];
  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 = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (s[i - 1] == t[j - 1]) {
        long long d_sum = 0;
        for (int k = 0; k < i; k++)
          for (int l = 0; l < j; l++) d_sum = (d_sum + dp[k][l]) % MOD;
        dp[i][j] = (d_sum + 1) % MOD;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) ans = (ans + dp[i][j]) % MOD;
  cout << (ans + 1) % MOD << endl;
}
