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

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