#include<bits/stdc++.h>
using namespace std;
const int N = 2009, Mod = 1e9 + 7;
int n, m, A[N], B[N], dp[N][N];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
        scanf("%d", &A[i]), dp[i][0] = 1;
    for (int i = 1; i <= m; i ++)
        scanf("%d", &B[i]), dp[0][i] = 1;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
        {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % Mod;
            dp[i][j] = (dp[i][j] + Mod - dp[i - 1][j - 1]) % Mod;
            if (A[i] == B[j])
                dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % Mod;
        }
    return !printf("%d\n", dp[n][m]);
}