#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

ll mod = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> S(N), T(M);
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 1));
    rep(i, N) rep(j, M) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
        if (S[i] != T[j]) dp[i + 1][j + 1] -= dp[i][j];
        dp[i + 1][j + 1] += mod;
        dp[i + 1][j + 1] %= mod;
    }
    cout << dp[N][M] << endl;
}