#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (auto &v : S) cin >> v;
  for (auto &v : T) cin >> v;
  vector<vector<long long int>> dp(N + 1, vector<long long int>(M + 1, 1));
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; 1 <= M; ++j) {
      dp[i][j] = dp[i][j - 1];
      for (int k = 1; k < i; ++k) {
        if (S[k - 1] == T[j - 1]) {
          dp[i][j] = (dp[i][j] + dp[k][j]) % 1000000007;
        }
      }
    }
  }
  cout << dp[N][M] << endl;
}
