using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace AtCoder
{
    class Abc162F
    {

        public static void Main()
        {
            var input = Console.ReadLine().Split(' ');
            long MOD = 10000000007;
            var m = int.Parse(input[0]);
            var n = int.Parse(input[1]);

            var mm = Console.ReadLine().Split(' ').Select(y => long.Parse(y)).ToArray();
            var nn = Console.ReadLine().Split(' ').Select(y => long.Parse(y)).ToArray();

            long[,] sum = new long[m + 1, n + 1];

            for (int i = 0; i <= m; i++)
                sum[i, 0] = 0;
            for (int i = 0; i <= n; i++)
                sum[0, i] = 0;

            for (int i = 1; i <= m; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    sum[i, j] = (sum[i - 1, j] + sum[i, j - 1] + MOD - sum[i - 1, j - 1]) % MOD;

                    if (mm[i - 1] == nn[j - 1])
                    {
                        sum[i, j] += (sum[i - 1, j - 1] + 1) % MOD;
                    }
                    sum[i, j] %= MOD;
                }
            }

            Console.Write((sum[m, n] + 1)%MOD);
            Console.WriteLine();

        }


    }
}
