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

static class Program
{
    static long Solve(int N, int M, int[] S, int[] T)
    {
        var dp = new long[N + 1][];
        for (int i = 0; i < N; ++i)
        {
            dp[i] = new long[M + 1];
            dp[i][M] = 1;
        }
        dp[N] = Enumerable.Repeat(1L, M + 1).ToArray();
        for (int i = N - 1; i >= 0; --i)
        {
            for (int j = M - 1; j >= 0; --j)
            {
                dp[i][j] = dp[i][j + 1] + dp[i + 1][j] - dp[i + 1][j + 1];
                if (S[i] == T[j]) { dp[i][j] += dp[i + 1][j + 1]; }
                dp[i][j] %= 1000000007;
            }
        }
        return dp[0][0];
    }

    static void Main(string[] args)
    {
        int[] V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] S = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] T = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(V1[0], V1[1], S, T));
    }
}
