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