#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
int a[100003],b[100003];
int dp[2003];
int main()
{
 int n,m;
 cin>>n>>m;
 for(int i=1;i<=n;i++)
 {
     cin>>a[i];
 }
 for(int i=1;i<=n;i++)
 {
   cin>>b[i];

 }

 for(int i=1;i<=n;i++)
 {ll ans=0;
     for(int j=1;j<=m;j++)
        if(a[i]==b[j])ans++;
        dp[i]=ans;
        
     dp[i]=dp[i]+(min(dp[j],dp[i-1]))%mod;
 }cout<<dp[n]+1<<endl;
}

