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