#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT = mp::cpp_int;
using namespace std;
using ll = long long;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define mod 1000000007ll
#define all(v) v.begin(), v.end()
#define putout(a) cout << a << endl
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M;
    cin >> N >> M;
    vector<INT> S(N), T(M);
    loop(i, N) cin >> S[i];
    loop(i, M) cin >> T[i];
    vector<vector<INT>> dp(N + 1, vector<INT>(M + 1));
    dp[0][0] = 1;
    Loop(i, -1, N)
    {
        Loop(j, -1, M)
        {
            if (i >= 0 && j >= 0 && S[i] == T[j])
                dp[i + 1][j + 1] += dp[i][j];
            if (i >= 0)
                dp[i + 1][j + 1] += dp[i][j + 1];
            if (j >= 0)
                dp[i + 1][j + 1] += dp[i + 1][j];
            if (i >= 0 && j >= 0)
                dp[i + 1][j + 1] -= dp[i][j];
        }
    }
    putout(dp[N][M] % mod);
    return 0;
}
