#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;
template<class T> void add(T &a, T b) { a = (a + b) % MOD; }

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    rep(i, 0, N) cin >> S[i];
    rep(i, 0, M) cin >> T[i];
    vector<vector<long long>> sum(N + 1, vector<long long>(M + 1));
    sum[N][M] = 1;
    rep(i, 0, N) rep(j, 0, M) {
        add(sum[i+1][j+1], sum[i+1][j] + sum[i][j+1] - sum[i][j] + MOD);
        if(S[i] == T[j]) add(sum[i+1][j+1], sum[i][j] + 1);
    }
    cout << sum[N][M] << endl;
    return 0;
}
