#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (auto& s : S) cin >> s;
  for (auto& t : T) cin >> t;
  const unsigned long MOD = 1e9 + 7;
  unsigned long dp[2][M + 1];
  for (int i = 0; i <= M; i++) dp[0][i] = 1;
  for (int i = 1; i <= N; i++) {
    auto dpi = i % 2;
    auto& cdp = dp[dpi];
    auto& pdp = dp[!dpi];
    cdp[0] = pdp[0];
    for (int j = 1; j <= M; j++) {
      cdp[j] = cdp[j - 1] + pdp[j];
      if (S[i - 1] != T[j - 1]) cdp[j] -= pdp[j - 1];
      cdp[j] %= MOD;
    }
  }
  cout << dp[N % 2][M] << endl;
  return 0;
}
