#include <bits/stdc++.h>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")

typedef long long ll;
typedef unsigned long long ull;
// typedef __int128_t lll;
#define fatnet ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll MOD1 = 1e9 + 7;
const ll MOD2 = 2000003983; // 3571 1e9 + 97
const ll MOD3 = 1e9 + 9;
const ll p1 = 1e6 + 3;
const ll p2 = 2017; // 131 37
const ll p3 = 37;
const ll INF = 5e18;

ll binpow(ll a, ll n, ll MOD) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return a * binpow(a, n - 1, MOD) % MOD;
    else
        return binpow(a * a % MOD, n / 2, MOD);
}

int main() {
    fatnet;

    ll n, m;
    cin >> n >> m;
    vector < ll > a(n);
    vector < ll > b(m);
    ll dp[n][m]{};
    ll sum[n + 1][m + 1]{};
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < m; ++i)
        cin >> b[i];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i] == b[j]) {
                dp[i][j] = (1 + sum[i][j]) % MOD1;
                sum[i + 1][j + 1] = (sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i][j]) % MOD1;
            }
            else {
                sum[i + 1][j + 1] = (sum[i + 1][j] + sum[i][j + 1] - sum[i][j]) % MOD1;
                dp[i][j] = 0;
            }
        }
    }
    ll ans = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            ans = (ans + dp[i][j]) % MOD1;
    cout << ans << "\n";

    return 0;
}
