#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MAXN = 2502;
ll dp[MAXN][MAXN];
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> S(n);
  vector<ll> T(m);
  for (auto& s : S) {
    cin >> s;
  }
  for (auto& t : T) {
    cin >> t;
  }
  for (ll i = 0; i < ll(MAXN); ++i) {
    dp[0][i] = dp[i][0] = 1;
  }
  for (ll i = 0; i < ll(n); ++i)
    for (ll j = 0; j < ll(m); ++j) {
      const auto& s = S[i];
      const auto& t = T[j];
      auto& dst = dp[i + 1][j + 1];
      dst += dp[i + 1][j];
      dst += dp[i][j + 1];
      dst -= (s == t ? 0 : dp[i][j]);
      dst %= MOD;
    }
  cout << dp[n][m] << endl;
  return 0;
}
