#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include<map>
#include <limits>
#include<iomanip>
#include<string>
#include<bitset>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
struct input{
  ll num;
  ll times;
  ll pre;
};
int main(void){
  ll n,m;
  cin>>n>>m;
  vector<input> s,t;
  ll ts,tt;
  rep(i,n){
    cin>>ts;
    s.push_back({ts,0,-1});
  }
  rep(i,m){
    cin>>tt;
    t.push_back({tt,0,-1});
  }
  vector<vector<ll>> dp1(m+1,vector<ll>(n+1,0));
  vector<vector<ll>> dp2(m+1,vector<ll>(n+1,0));
    rep(i,m){
      rep(j,n){
        if(s[j].num==t[i].num){
          dp1[i+1][j+1]+=dp2[i][j]+1;
        }else{
          dp1[i+1][j+1]=0;
        }
        dp1[i+1][j+1]%=d9_7;dp2[i+1][j+1]%=d9_7;

          dp2[i+1][j+1]=(dp2[i][j+1]%d9_7+dp2[i+1][j]%d9_7)%d9_7-dp2[i][j%d9_7+dp1[i+1][j+1]%d9_7;
        dp1[i+1][j+1]%=d9_7;dp2[i+1][j+1]%=d9_7;
      }
    }
  /*rep(i,m){
    rep(j,n){
      cout<<dp[i+1][j+1]<<" ";
    }
    cout<<endl;
  }*/
  cout<<(dp2[m][n]+1)%d9_7<<endl;
  return 0;
}