#include <iostream>
#include <cstdint>

using namespace std;

const u_int64_t R = 1'000'000'007;

u_int64_t dp[2'000][2'000];
u_int64_t p[2'000][2'000];
int s[2'000], t[2'000];

int main()
{
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> t[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            dp[i][j] = s[i] == t[j] ? (p[i - 1][j - 1] + 1) % R : 0;

            u_int64_t a = 0;
            a = (a + (i == 0 ? 0 : p[i - 1][j])) % R;
            a = (a + (j == 0 ? 0 : p[i][j - 1])) % R;
            a = (a + R - (i == 0 || j == 0 ? 0 : p[i - 1][j - 1])) % R;
            a = (a + dp[i][j]) % R;
            p[i][j] = a;
        }
    }

    cout << (p[n - 1][m - 1] + 1) % R << endl;

    return 0;
}
