import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] S = new int[N];
		int[] T = new int[M];
		
		for(int i=0; i<N; i++)
			S[i] = sc.nextInt();
		for(int i=0; i<M; i++)
			T[i] = sc.nextInt();
		
		final long MOD = 1000000007;
		long[][] dp = new long[N+1][M+1];
		long[][] sum = new long[N+1][M+1];
		dp[0][0] = 1;
		sum[0][0] = 1;
		for(int i=0; i<N+1; i++) {
			for(int j=0; j<M+1; j++) {
				if(i>0 && j>0 && S[i-1]==T[j-1])
					dp[i][j] = sum[i-1][j-1];
				sum[i][j] = ((i>0 ? sum[i-1][j] : 0) + (j>0 ? sum[i][j-1] : 0) - (i>0 && j>0 ? sum[i-1][j-1] : 0) + dp[i][j] + MOD) % MOD;
			}
		}
		
		System.out.println(sum[N][M]);
		sc.close();
	}
}
