#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int dp[2020][2020];
int N, M, S[2020], T[2020];
int main(void) {
  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 = 0; i <= N; i++) {
    dp[i][0] = 1;
  }
  for (int j = 0; j <= M + 1; j++) {
    dp[0][j] = 1;
  }
  for (int n = 1; n <= N; n++) {
    for (int m = 1; m <= M; m++) {
      dp[n][m] = dp[n][m - 1];
      for (int k = 1; k <= n; k++) {
        if (T[m] == S[k]) {
          dp[n][m] += dp[k - 1][m - 1];
          dp[n][m] %= MOD;
        }
      }
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
