#include<bits/stdc++.h>
using namespace std;
int main() {
  using LL = long long;
  const LL MOD = 1e9+7;
  int N, M;
  cin >> N >> M;
  vector<LL> S(N), T(M);
  for(auto v: {&S, &T}) for(auto& i: *v) cin >> i;
  vector<vector<LL>> dp(N+1, vector<LL>(M+1));
  for(auto i=1; i<=N; ++i) for(auto j=1; j<=M; ++j) {
    dp[i][j] += dp[i-1][j] + dp[i][j-1];
    dp[i][j] += (S[i-1]==T[j-1] ? 1 : -dp[i-1][j-1]);
    dp[i][j] %= MOD;
  }
  cout << (1 + dp[N][M] + MOD) % MOD << endl;
}
