#include <iostream>
#include <vector>
using namespace std;

const long long MOD = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n);
    vector<int> t(m);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < m; i++) cin >> t[i];

    vector<vector<long long> > dp(n + 1, vector<long long>(m + 1, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + MOD) % MOD;
            if (s[i] == t[j]) (dp[i + 1][j + 1] += dp[i][j] + 1) % MOD;
        }
    }

    cout << (dp[n][m] + 1) % MOD << endl;
    return 0;
}