#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
ll a[2003],b[2003];
ll dp[2003][2003];
int main()
{
 int n,m;
 cin>>n>>m;
 for(int i=1;i<=n;i++)
    cin>>a[i];
 for(int j=1;j<=m;j++)
    cin>>b[j];
 for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
 { dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod;
   if(a[i]==b[j])dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;}
   cout<<(dp[n][m]+1+mod)%mod;
}

