#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    constexpr ll mod = 1e9 + 7;
    int n, m; cin >> n >> m;
    vector<int> s(n), t(m);
    REP(i, n) cin >> s[i];
    REP(i, m) cin >> t[i];

    auto dp = make_v(n+1, m+1, 0LL);
    REP(i, n+1) dp[i][0] = 1;
    REP(i, m+1) dp[0][i] = 1;
    FOR(i, 1, n+1)FOR(j, 1, m+1){
        if(s[i-1] == t[j-1]){
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
        } else {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod;
        }
    }
    
    cout << dp[n][m] << endl;

    return 0;
}
