using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main()
	{
		int N = GetInt();
		int M = GetInt();
		int[] S = Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
		int[] T = Enumerable.Range(0, M).Select(_ => GetInt()).ToArray();

		long mod = (long)1e9 + 7;
		long[,] dp = new long[N + 1, M + 1];
		long[,] csum = new long[N + 1, M + 1];
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < M; j++)
			{
				dp[i + 1, j + 1] = (S[i] == T[j]) ? (csum[i, j] + 1) % mod : 0;
				csum[i + 1, j + 1] = (csum[i, j + 1] + csum[i + 1, j] - csum[i, j] + dp[i + 1, j + 1]) % mod;
			}
		}

		Console.WriteLine((csum[N, M] + 1) % mod);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}



