#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
input:
    ll n, m;
    cin >> n >> m;

    ll s[n];
    ll t[m];
    rep(i, n) { cin >> s[i]; }
    rep(i, m) { cin >> t[i]; }

calculate:
    ll dp[n + 1][m + 1] = {};
    rep(i, m + 1) { dp[0][i] = 1; }
    rep(i, n + 1) { dp[i][0] = 1; }

    repd(i, 1, n + 1) {
        repd(j, 1, m + 1) {
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
            if (dp[i][j] > mod) {
                dp[i][j] -= mod;
            }

            if (s[i - 1] != t[j - 1]) {
                dp[i][j] -= dp[i - 1][j - 1];
            }
            if (dp[i][j] > mod) {
                dp[i][j] -= mod;
            }
        }
    }

    dp[n][m] %= mod;
    cout << dp[n][m] << endl;
    return 0;
}

