#include <iostream>
typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  ll S[N], T[M];
  ll dp[N+1][M+1] = {};
  for (int i=0; i<N; i++) cin >> S[i];
  for (int i=0; i<M; i++) cin >> T[i];

  for (int i=1; i<=N; i++) {
    for (int j=1; j<=M; j++) {
      // S[i], T[j]
      dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + (S[i-1] == T[j-1]) * (dp[i-1][j-1] + 1)) % MOD;

    }
  }
  cout << (dp[N][M] + 1) % MOD << endl;
}
