#include<bits/stdc++.h>
using namespace std;

const int MOD = 1'000'000'007;
const int MAXN = 2000;

int arr[MAXN];
int kek[MAXN];

int dp1[MAXN + 1][MAXN + 1];
int dp2[MAXN + 1][MAXN + 1];
int ok1[MAXN + 1][MAXN + 1];
int ok2[MAXN + 1][MAXN + 1];

int rec2(int n, int m)
{
    if (ok2[n][m])
        return dp2[n][m];
    ok2[n][m] = 1;
    
    if (n * m == 0)
        dp2[n][m] = 1;
    else
        dp2[n][m] = (rec2(n, m - 1) + rec2(n - 1, m) - rec2(n - 1, m - 1) + dp1[n][m]) % MOD;
    
    return dp2[n][m];
}

int rec1(int n, int m)
{
    if (ok1[n][m])
        return dp1[n][m];
    ok1[n][m] = 1;
    
    if (arr[n - 1] == kek[m - 1])
        dp1[n][m] = rec2(n - 1, m - 1);
    
    return dp1[n][m];
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i != n; ++i)
        cin >> arr[i];
    for (int i = 0; i != m; ++i)
        cin >> kek[i];
    dp1[0][0] = 1;
    dp2[0][0] = 1;
    ok1[0][0] = 1;
    ok2[0][0] = 1;
    int ans = 1;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            ans = (ans + rec1(i, j)) % MOD;
    cout << ans << '\n';
}