#include <bits/stdc++.h>
using namespace std;
int S[4010];
int T[4010];
int dp[4010][4010];
const int MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> S[i];
  for (int i = 1; i <= m; i++) cin >> T[i];
  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]) % MOD;
      if (S[i] == T[j]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MOD;
    }
  }
  int ans = (dp[n][m] + 1) % MOD;
  cout << ans << endl;
}
