#include <bits/stdc++.h>
using namespace std;
long long N, M;
long long inf = 1e9 + 7;
int main() {
  cin >> N >> M;
  vector<int> S(N + 1, 0), T(N + 1, 0);
  for (int i = 1; i <= N; i++) cin >> S[i];
  for (int j = 1; j <= M; j++) cin >> T[j];
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1, 0));
  vector<vector<long long>> sum(N + 1, vector<long long>(M + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i != 0 && j != 0 && S[i] == T[j])
        (dp[i][j] += sum[i - 1][j - 1]) %= inf;
      (sum[i][j] += dp[i][j]) %= inf;
      if (j != 0) (sum[i][j] += sum[i][j - 1]) %= inf;
    }
    if (i != 0)
      for (int j = 0; j <= M; j++) (sum[i][j] += sum[i - 1][j]) %= inf;
  }
  cout << sum[N][M] << endl;
}
