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

namespace Competitive
{
    internal class Solution
    {
        public int N, M;
        public int[] S, T;
        public long MOD = 1000000007;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                M = line[1];
            }
            S = Input.ReadIntArray();
            T = Input.ReadIntArray();

            long[,] DP = new long[N + 1, M + 1];

            // TODO 速度が足りないので、Dictionary?
            DP[0, 0] = 1;
            for (int s = 0; s <= N; s++)
            {
                DP[s, 0] = 1;
            }

            for (int t = 0; t < M; t++)
            {
                DP[0, t] = 1;
            }

            for (int s = 1; s <= N; s++)
            {
                for (int t = 1; t <= M; t++)
                {
                    long count = 0;

                    count += DP[s, t - 1];

                    for (int ss = 1; ss <= s; ss++)
                    {
                        int cht = T[t - 1];
                        int chs = S[ss - 1];
                        if (cht == chs)
                        {
                            count += DP[ss - 1, t - 1];
                        }
                    }
                    count %= MOD;
                    DP[s, t] = count;
                }
            }

            Console.WriteLine(DP[N, M]);
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}