#include <bits/stdc++.h>
using namespace std;
using int32 = int_fast32_t;
using int64 = int_fast64_t;
const int32 INF = 1e9;
const int32 MOD = 1e9 + 7;
const int64 LLINF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 n, m;
  cin >> n >> m;
  int64 s[n], t[m];
  for (int64 i = 0; i < (n); ++i) cin >> s[i];
  for (int64 j = 0; j < (m); ++j) cin >> t[j];
  vector<vector<int64>> dp(n + 1, vector<int64>(m + 1));
  vector<vector<int64>> sum(n + 1, vector<int64>(m + 1, 1));
  for (int64 i = (1); i < (n + 1); i++)
    for (int64 j = (1); j < (m + 1); j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = sum[i - 1][j - 1];
        dp[i][j] %= MOD;
      } else {
        dp[i][j] = 0;
      }
      sum[i][j] = ((sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1]) % MOD +
                   dp[i][j]) %
                  MOD;
    }
  cout << (sum[n][m] % MOD) << "\n";
  return 0;
}
