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