//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 4005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,dp[li];
lo cev;
string s;
vector<int> v;

inline lo add(lo x,lo y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

int main(void){
	scanf("%lld %lld",&n,&m);
	FOR{
		scanf("%lld",&a[i]);
	}
	for(lo i=0;i<m;i++){
		scanf("%lld",&b[i]);
	}
	for(lo i=0;i<=n+m+1;i++){
		dp[i]=1;
	}
	for(lo i=n;i>=1;i--){
		//~ for(lo j=i;j<m+i;j++){
			if ((i & 7) || (j & 7)) {
				if(a[n-i]==b[j-i]){
					dp[j]=(add(dp[j-1],dp[j+1]))%mod;
				}
				else{
					dp[j]=(add(dp[j-1],dp[j+1])-dp[j])%mod;
				}
			//~ }
			//~ else{
				//~ if(a[n-i]==b[j-i]){
					//~ dp[j]=((dp[j-1]+dp[j+1]));
				//~ }
				//~ else{
					//~ dp[j]=(dp[j-1]+dp[j+1]-dp[j]);
				//~ }
			//~ }
		}
	}
	printf("%lld\n",(dp[m]%mod+mod)%mod);
	return 0;
}
