#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
const int mod=1000000007;
int n,m;
int s[2002],t[2002];
int dp[2002][2002];

int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++)
		cin>>s[i];
	for (int i=1;i<=m;i++)
		cin>>t[i];
	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++){
		dp[i][j]=(dp[i-1][j]+dp[i][j-1]-(s[i]==t[j]?0:dp[i-1][j-1]))%mod;
		dp[i][j]=(dp[i][j]+mod)%mod;
	}
	cout<<dp[n][m]%mod<<endl;
	return 0;
}