#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1e9 + 7;
int s[1010], t[1010];
long long dp[1010][1010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> s[i];
  for (int j = 1; j <= m; ++j) cin >> t[j];
  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] - dp[i - 1][j - 1];
      dp[i][j] %= MOD;
      if (s[i] == t[j]) {
        dp[i][j] += dp[i - 1][j - 1] + 1;
        dp[i][j] %= MOD;
      }
    }
  }
  if (dp[n][m] < 0) dp[n][m] += MOD;
  cout << (dp[n][m] + 1) % MOD << endl;
  return 0;
}
