#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
int main() {
  ll N, M;
  cin >> N >> M;
  vll s(N);
  for (ll i = 0; i < (ll)N; ++i) {
    cin >> s[i];
  }
  vll t(M);
  for (ll i = 0; i < (ll)M; ++i) {
    cin >> t[i];
  }
  vvll dpl(N, vll(M, -1));
  function<ll(ll, ll)> fl = [&](ll ls, ll lt) {
    if (ls < 0 || lt < 0) return 0ll;
    if (dpl[ls][lt] >= 0) {
      return dpl[ls][lt];
    }
    ll count = 0;
    for (ll i = lt; i >= 0; --i) {
      if (t[i] == s[ls]) {
        ++count;
        for (ll j = 0; j < (ll)ls; ++j) {
          count += fl(j, i - 1);
        }
      }
    }
    dpl[ls][lt] = count % 1000000007;
    return dpl[ls][lt];
  };
  ll count = 0;
  for (ll i = 0; i < (ll)N; ++i) {
    count = (count + fl(i, M - 1)) % 1000000007;
  }
  count = (count + 1) % 1000000007;
  cout << count << endl;
}
