#include<bits/stdc++.h>

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    size_t N, M;
    cin >> N >> M;
    vector<unsigned long> S(N), T(M);
    copy_n(istream_iterator<unsigned long>(cin), N, S.begin());
    copy_n(istream_iterator<unsigned long>(cin), M, T.begin());
    vector<vector<unsigned long>> dp(N + 1, vector<unsigned long>(M + 1));
    for(size_t i = 0; i != N; ++i)for(size_t j = 0; j != M; ++j)dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + (S[i] != T[j] ? MOD - dp[i][j] : 1)) % MOD;
    cout << dp.back().back() + 1 << endl;
    return 0;
}