#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  long long dp[N + 1][M + 1];
  vector<int> nums_T[100001];
  vector<int> nums_S[100001];
  for (int i = 0; i < M; i++) {
    nums_T[T[i]].push_back(i);
  }
  for (int i = 0; i < N; i++) {
    nums_S[S[i]].push_back(i);
  }
  for (int i = 0; i <= N; i++) {
    dp[i][0] = 1;
  }
  for (int i = 0; i <= M; i++) {
    dp[0][i] = 1;
  }
  for (int n = 1; n <= N; n++) {
    for (int m = 1; m <= M; m++) {
      dp[n][m] = dp[n - 1][m] + dp[n][m - 1];
      if (S[n - 1] != T[m - 1]) dp[n][m] -= dp[n - 1][m - 1];
      dp[n][m] %= mod;
    }
  }
  cout << dp[N][M] % mod << endl;
  return 0;
}
