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

namespace ABC130E3
{
    class Program
    {
        static long[,] arr;
        static void Main(string[] args)
        {
            long mod = (long)Math.Pow(10, 9) + 7;
            string[] input = Console.ReadLine().Split();
            long N = int.Parse(input[0]);
            long M = int.Parse(input[1]);
            string[] S = Console.ReadLine().Split().ToArray();
            string[] T = Console.ReadLine().Split().ToArray();
            arr = new long[M, N];
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (S[j]==T[i])
                    {
                        arr[i,j] = 1;
                    }
                    else
                    {
                        arr[i, j] = 0;
                    }
                    //Console.Write(arr[i,j]+" ");
                }
                //Console.WriteLine();
            }
            long[,] arr2 = new long[M, N];
            long answer = 0;
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (arr[i,j]==1)
                    {
                        arr2[i, j] = sum(i, j) + arr[i, j];
                        arr[i, j] = arr2[i, j];
                        answer += arr[i, j]%mod;
                    }
                    else
                    {
                        arr2[i, j] = 0;
                    }
                    //Console.Write(arr2[i,j]+" ");  
                }
                //Console.WriteLine();
            }
            Console.WriteLine((answer+1)%mod);

        }
        static long sum(long x,long y)
        {
            long ans = 0;
            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    ans += arr[i, j];
                }
            }
            return ans;
        }
    }
}
