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

namespace Q5
{
    class Program
    {
        static void Main(string[] args)
        {
            long divide = (long)Math.Pow(10, 9) + 7;
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int N = int.Parse(strs[0]);
            int M = int.Parse(strs[1]);
            long[] S = new long[N];
            long[] T = new long[M];
            line = Console.ReadLine();
            strs = line.Split(' ');
            for (int i = 0; i < N; i++)
            {
                S[i] = long.Parse(strs[i]);
            }
            line = Console.ReadLine();
            strs = line.Split(' ');
            for (int i = 0; i < M; i++)
            {
                T[i] = long.Parse(strs[i]);
            }
            long count = 0;

            long[,] dp = new long[N, M];
            long[,] sum = new long[N, M];
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    dp[i, j] = 0;
                }
            }
            for (int i = 0; i < N; i++)
            {
                for(int j = 0; j < M; j++)
                {
                    if (S[i] == T[j])
                    {
                        dp[i, j] = 1;
                        if (i > 0 && j > 0) dp[i, j] += sum[i - 1, j - 1];
                    }
                    sum[i, j] = dp[i, j];
                    sum[i, j] %= divide;
                    if (i > 0) sum[i, j] += sum[i - 1, j];
                    sum[i, j] %= divide;
                    if (j > 0) sum[i, j] += sum[i, j - 1];
                    sum[i, j] %= divide;
                    if (i > 0 && j > 0) sum[i, j] -= sum[i - 1, j - 1];
                    sum[i, j] %= divide;
                }
            }
            count = sum[N-1, M-1] + 1;
            Console.WriteLine(count % divide);
        }
    }
}
