#include<bits/stdc++.h>
#define gc getchar
#define re register
#define rep(i,s,t) for(re int i=s;i<=t;++i)
 
using namespace std;
typedef long long ll;
 
const int N=2005;
const ll Mod=1e9+7;
int n,m,s[N],t[N];
ll dp[N][N];
 
inline int read(){
  int rt=0;
  char ch=gc();
  while(ch<'0'||ch>'9')ch=gc();
  while(ch>='0'&&ch<='9'){
    rt=(rt<<3)+(rt<<1)+(ch&15);
    ch=gc();
  }
  return rt;
}
int main(){
  n=read(),m=read();
  rep(i,1,n)s[i]=read();
  rep(i,1,m)t[i]=read();
  rep(i,0,n)dp[i][0]=1;
  rep(j,0,m)dp[0][j]=1;
  rep(i,1,n)rep(j,1,m)dp[i][j]=((dp[i-1][j]+dp[i][j-1]-(s[i]==t[j]?0ll:dp[i-1][j-1]))%Mod+Mod)%Mod;
  return not printf("%lld",dp[n][m]);
}