#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), b(m);
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  vector<vector<ll>> dp(n + 1);
  for (auto &i : dp) i.resize(m + 1);
  for (ll i = 0; i <= n; i++) dp[i][0] = 0;
  for (ll i = 0; i <= m; i++) dp[0][i] = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (a[i - 1] == b[j - 1]) dp[i][j] += dp[i - 1][j - 1] + 1;
      dp[i][j] %= (ll)(1e9 + 7);
    }
  }
  cout << dp[n][m] + 1 << "\n";
  return 0;
}
