#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  vector<long long> b(m);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long j = 0; j < m; ++j) cin >> b[j];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + mod) % mod;
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] += (1 + dp[i - 1][j - 1]) % mod;
      }
    }
  }
  cout << dp[n][m] + 1;
}
