#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll=long long;
ll mo=7+1e9;
int main(){
ll n,m; cin>>n>>m;
ll a[n],b[m]; rep(i,n) cin>>a[i];rep(j,m)cin>>b[j];
vector<vector<ll>>s(1e4,vector<ll>(1e4,1));
rep(i,n)rep(j,m)s[i+1][j+1]=(s[i+1][j]+mo+s[i][j+1]+(a[i]==b[j]?0:-s[i][j]))%mo;
cout<<s[n][m];
}