#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long i = 0; i < m; ++i) cin >> b[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  for (long long i = 1; i < n + 1; ++i) {
    for (long long j = 1; j < m + 1; ++j) {
      if (a[i - 1] == b[j - 1])
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << (dp[n][m] % 1000000007 + 1) % 1000000007;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) solve();
  cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs"
       << "\n";
  cerr << "My CLOCKS_PER_SEC= " << CLOCKS_PER_SEC << "\n";
  return 0;
}
