#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 long MOD = 1e9 + 7;
  vector<vector<long>> dp(N + 1, vector<long>(M + 1, 0));
  for (int i = 0; i <= N; i++) dp[i][0] = 1;
  for (int j = 1; j <= M; j++) dp[0][j] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      if (S[i - 1] != T[j - 1]) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp.back().back() << endl;
  return 0;
}
