using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string[] s1 = Console.ReadLine().Split(' ');
            int n = int.Parse(s1[0]), m = int.Parse(s1[1]);
            int[] s = new int[n];
            string[] s2 = Console.ReadLine().Split(' ');
            for (int i=0; i<n; i++) s[i] = int.Parse(s2[i]);
            int[] t = new int[m];
            string[] s3 = Console.ReadLine().Split(' ');
            for (int i=0; i<m; i++) t[i] = int.Parse(s3[i]);

            int mod = 1000000007;

            int[,] dp = new int[n+1, m+1];
            for (int i=0; i<=n; i++) dp[i, 0] = 1;
            for (int i=0; i<=m; i++) dp[0, i] = 1;
            for (int i=1; i<=n; i++)
            {
                for (int j=1; j<=m; j++)
                {
                    if (s[i-1] == t[j-1]) dp[i, j] = dp[i-1, j] + dp[i, j-1];
                    else dp[i, j] = dp[i-1, j] + dp[i, j-1] - dp[i-1, j-1];
                    dp[i, j] %= mod;
                }
            }
            Console.WriteLine(dp[n, m]);
        }
    }