#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005];
int arr1[2005];
int arr2[2005];

int mod = 1e9+7;
int main(){
  int m,n;
  cin>>m>>n;
  
  for(int i=0;i<m;++i)cin>>arr1[i];
  for(int i=0;i<n;++i)cin>>arr2[i];
  
  for(int i=0;i<2005;++i){
    dp[i][0] = 0;
    dp[0][i] = 0;
  }
  
  for(int i=0;i<m;++i){
    for(int j=0;j<n;++j){
      dp[i+1][j+1] = ((dp[i][j+1] + dp[i+1][j])%mod + mod - dp[i][j])%mod;
      
      if(arr1[i]==arr2[j]){
        dp[i+1][j+1] += 1;
        dp[i+1][j+1] += dp[i][j];
        dp[i+1][j+1] =  dp[i+1][j+1]%mod;
      }
    }
  }
  
  cout<<dp[m][n]+1<<endl;
  return 0;
}