#include <cstdio>
#include <vector>

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
    ll n, m;
    scanf("%lld%lld", &n, &m);
    vector<ll> s(n + 1), t(m + 1);
    for (ll i = 1; i <= n; ++i) scanf("%lld", &s.at(i));
    for (ll i = 1; i <= m; ++i) scanf("%lld", &t.at(i));
    vector< vector<ll> > dp(n + 1, vector<ll>(m + 1));
    for (ll i = 1; i <= n; ++i) for (ll j = 1; j <= m; ++j) dp.at(i).at(j) = dp.at(i - 1).at(j) + dp.at(i).at(j - 1) + (s.at(i) == t.at(j) ? 1 : -dp.at(i - 1).at(j - 1)), dp.at(i).at(j) += MOD, dp.at(i).at(j) %= MOD;
    printf("%lld\n", (dp.at(n).at(m) + 1) % MOD);
    return 0;
}
