#include<bits/stdc++.h>
using namespace std;

int main() {
  using LL = long long;
  using P = pair<int, int>;

  const LL MOD = 1e9+7;

  int N, M;
  cin >> N >> M;
  vector<LL> S(N), T(M);
  for(auto v: {&S, &T}) for(auto& i: *v) cin >> i;

  map<P, LL> memo;
  function<LL(P)> dfs = [&](const auto& p) {
    if(memo.count(p)) return memo[p];
    auto s = p.first;
    auto t = p.second;
    LL res = 0;
    for(auto s=p.first+1; s<N; ++s)
      for(auto t=p.second+1; t<M; ++t)
        if(S[s]==T[t]) (res += 1 + dfs({s, t})) %= MOD;
    return memo[p] = res;
  };
  cout << (1 + dfs({-1, -1})) % MOD << endl;
}
