using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    static void Main()
    {
        var NM = Console.ReadLine().Split(' ').Select(n => Int64.Parse(n)).ToArray();
        var N = NM[0];
        var M = NM[1];
        var S = Console.ReadLine().Split(' ').Select(n => Int64.Parse(n)).ToArray();
        var T = Console.ReadLine().Split(' ').Select(n => Int64.Parse(n)).ToArray();

        var mod = 1000000007L;
        var dp = new long[N + 1, M + 1];

        dp[0, 0] = 1;
        for (int i = 1; i <= N; ++i) dp[i, 0] = 1;
        for (int i = 1; i <= M; ++i) dp[0, i] = 1;

        for (int i = 1; i <= N; ++i)
        {
            for (int j = 1; j <= M; ++j)
            {
                if (S[i - 1] == T[j - 1]) dp[i, j] = dp[i - 1, j - 1];
                dp[i, j] = dp[i - 1, j] + dp[i, j - 1] - dp[i - 1, j - 1];
                dp[i, j] %= mod;
            }
        }
        Console.WriteLine(dp[N, M]);
    }
}
