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

#define int long long
#define rep(i,a,b) for(int i = a; i < b; i++)
const int mod = 1e9 + 7;

signed main() {
    int N, M;
    cin >> N >> M;
    int S[N];
    rep(i,0,N) cin >> S[i];
    int T[M];
    rep(j,0,M) cin >> T[j];

    int dp[N+1][M+1];
    rep(i,0,N+1) {
        rep(j,0,M+1) {
            if (i == 0 || j == 0) {
                dp[i][j] = 1;
            }
            else {
                dp[i][j] = 0;
            }
        }
    }

    rep(i,1,N+1) {
        rep(j,1,M+1) {
            if (S[i-1] == T[j-1]) {
                dp[i][j] = dp[i][j-1] + dp[i-1][j];
            }
            else {
                dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1];
            }
            dp[i][j] = (dp[i][j] + mod) % mod
        }
    }

    int ans = dp[N][M];
    cout << ans << endl;
}