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