#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
#define deb(x) each(x.begin(),x.end(),(int& y){cout << y <<" ";})
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  int N,M; cin>>N>>M;
  int s[N],t[M]; //sとtの最長共通部分列

  rep(i,N){
    cin>>s[i];
  }
  rep(i,M){
    cin>>t[i];
  }

  ll dp[N+1][M+1]={};
  rep(i,N+1){
    rep(j,N+1){
      if(i==0 or j==0) dp[i][j]=1;
    }
  }

  dp[0][0]=1;

  reps(i,1,N+1){
    reps(j,1,M+1){
      if(s[i-1]==t[j-1]) dp[i][j] += dp[i-1][j-1];
      dp[i][j]+=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
      dp[i][j]+=MOD;
      dp[i][j]%=MOD;
      //cout<< i <<" "<<j <<"\n";
      //db(dp[i][j]);
    }
  }
  cout<< dp[N][M] <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------
