#include<bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int main()
{
  int n,m;
  cin>>n>>m;
  int i,j,s[n],t[m];
  for(i=0;i<n;i++) cin>>s[i];
  for(i=0;i<m;i++) cin>>t[i];
  
  int dp[n+1][m+1];
  memset(dp, 0, sizeof(dp));
  
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=m;j++)
    {
   		dp[i][j]=(dp[i-1][j]+ dp[i][j-1])%mod;
      	dp[i][j]= (dp[i][j]-dp[i-1][j-1]+mod)%mod;
      	if(s[i-1]==t[j-1])
        {
          dp[i][j]=(dp[i][j]+1+dp[i-1][j-1])%mod;
        }
    }
  }
  cout<<(dp[n][m]+1)%mod;
  return 0;
}