#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
int dp[2140][2140];
int sum[2140][2140];
signed main(){
	int n,m;
	cin>>n>>m;
	vector<int> s,t;
	for(int i=0;i<n;i++){int x;cin>>x;s.pb(x);}
	for(int i=0;i<m;i++){int x;cin>>x;t.pb(x);}
	dp[0][0]=1;
	for(int i=0;i<=max(n.m);i++){
		sum[i][0]=1;
		sum[0][i]=1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1] == t[j-1]){
				dp[i][j] = sum[i-1][j-1];
				sum[i][j] = sum[i-1][j]+sum[i][j-1]+dp[i][j]-sum[i-1][j-1];
				dp[i][j] %= inf;
				sum[i][j] %= inf;
			}
			else{
				sum[i][j] = sum[i-1][j]+sum[i][j-1]+dp[i][j]-sum[i-1][j-1];
				sum[i][j] %= inf;
			}
			//cout<<dp[i][j]<<endl;
		}
	}
	cout<<sum[n][m]<<endl;
	return 0;
}