#include<cstdio>

const int p = 1000000007;
const int MAX_N = 2000;
const int MAX_LEN = 100000;

long long dp[MAX_N+1][MAX_N+1];
int s[MAX_LEN], t[MAX_LEN];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	dp[0][0] = 1;
	for(int i=0;i<n;i++) {
		scanf("%d", &s[i]);
		dp[i+1][0] = 1;
	}
	for(int i=0;i<m;i++) {
		scanf("%d", &t[i]);
		dp[0][i+1] = 1;
	}
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
		dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1];
		if(s[i] != t[j]) dp[i+1][j+1] += p - dp[i][j];
		dp[i+1][j+1] %= p;
	}
	printf("%d\n", dp[n][m]);
	return 0;
}
