#include<bits/stdc++.h>
using namespace std;

int mod = 1'000'000'007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    vector<int> t(m);
    for (int i = 0; i < m; i++) cin >> t[i];
    vector<vector<long long>> ans(n+1, vector<long long>(m+1, 1));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (s[i] == t[j]){
                ans[i+1][j+1] = ans[i+1][j] + ans[i][j+1];
            }
            else {
                ans[i+1][j+1] = ans[i+1][j] + ans[i][j+1] - ans[i][j];
            }
            ans[i+1][j+1] %= mod;
        }
    }
    cout << ans[n][m] << endl;
}