#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

#define rep(i,m,n) for(ll i=m;i<n;i++)

const ll mod=1000000007;

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);

 ll n,m;
  cin >> n >> m;
  vector<ll> s(n),t(m);
  rep(i,0,n) cin >> s[i];
  rep(i,0,m) cin >> t[i];
  
  vector<vll> dp(n+1,vll(m+1,0));
  rep(i,0,n+1) dp[i][0]=1;
  rep(i,0,m+1) dp[0][i]=1;
  
  rep(i,0,n){ 
    rep(j,0,m) {
      dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%mod;
      if(s[i]!=t[j]) dp[i+1][j+1]+=mod-dp[i][j];
      dp[i+1][j+1]%=mod;
                    }
  }
cout << dp[n][m] << endl;
  
}
