#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX_N = 2333;
const ll MOD = 1e9 + 7;

int N, M;
int S[MAX_N], T[MAX_N];
ll f[MAX_N][MAX_N];

int main() {
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= N; i++) scanf("%d", &S[i]);
    for (int i = 1; i <= M; i++) scanf("%d", &T[i]);
    for (int i = 0; i <= N; i++) f[i][0] = 1;
    for (int i = 0; i <= M; i++) f[0][i] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD;
            if (S[i] != T[j]) (f[i][j] += MOD - f[i - 1][j - 1]) %= MOD;
        }
    }
    printf("%lld\n", f[N][M]);
}
