#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
const int mod = 1e9+7;

int main(){
  int n, m;
  cin >> n >> m;
  int s[n];
  int t[m];
  rep(i, n) cin >> s[i];
  rep(i, m) cin >> t[i];
  vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
  rep(i,n){
    rep(j,m){
      if(s[i] == t[j]) dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] + 1) % mod;
      else dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % mod;
    }
  }
  int ans = ((dp[n][m] + 1) % mod  + mod) % mod;
  cout << ans << endl;
  return 0;
}
