#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 7;
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n + 1], b[n + 1], dp[N][N] = {{0}};
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 1; j <= m; j++) cin >> b[j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i] != b[j]) {
        dp[i][j] =
            (dp[i - 1][j] % MOD + dp[i][j - 1] % MOD - dp[i - 1][j - 1] % MOD);
        dp[i][j] %= MOD;
      } else
        dp[i][j] = (1 + dp[i - 1][j] % MOD + dp[i][j - 1] % MOD);
      dp[i][j] %= MOD;
    }
  }
  cout << (dp[n][m] + 1) % MOD << endl;
  return 0;
}
