import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    long[][] DP, SUM;
    DP.length = N;
    SUM.length = N;
    foreach (i; 0..N) {
        DP[i].length = M;
        SUM[i].length = M;
    }
    auto SS = readln.split.to!(long[]);
    auto TS = readln.split.to!(long[]);

    foreach (i; 0..N) {
        foreach (j; 0..M) {
            if (SS[i] == TS[j]) {
                DP[i][j] = ((i > 0 && j > 0 ? SUM[i-1][j-1] : 0) + 1) % P;
            }
            SUM[i][j] = (
                (i > 0 ? SUM[i-1][j] : 0)
                + (j > 0 ? SUM[i][j-1] : 0)
                - (i > 0 && j > 0 ? SUM[i-1][j-1] : 0)
                + DP[i][j]
            ) % P;
        }
    }

    long r;
    foreach (i; 0..N) foreach (j; 0..M) r = (r + DP[i][j]) % P;

    writeln((r + 1) % P);
}