using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		long[]S = new long[N];
		long[]T = new long[M];
		string[] str2 = Console.ReadLine().Split();
		string[] str3 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			S[i] = long.Parse(str2[i]);
		}
		for(var i=0;i<M;i++){
			T[i] = long.Parse(str3[i]);
		}
		long mod = 1000000007;
		long[,]D = new long[N+1,M+1];
		for(var i=0;i<N;i++){
			for(var j=0;j<M;j++){
				if(S[i]==T[j]){
					D[i+1,j+1] = (D[i,j+1]+D[i+1,j]+1) % mod;
				} else {
					D[i+1,j+1] = (D[i,j+1]+D[i+1,j]-D[i,j]) % mod;
				}
			}
		}
		Console.WriteLine((D[N,M]+1)%mod);
	}
}