#include <bits/stdc++.h>
using namespace std;
int main() {
  int MOD = 1e9 + 7;
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  vector<int> T(M);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> T[i];
  }
  vector<vector<int>> f(N + 1, vector<int>(N + 1));
  for (int i = 0; i <= N; ++i) {
    f[i][0] = 1;
  }
  for (int j = 0; j <= M; ++j) {
    f[0][j] = 1;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      f[i][j] = f[i - 1][j];
      for (int k = 1; k <= j; ++k) {
        if (S[i - 1] == T[k - 1]) {
          f[i][j] = (f[i][j] + f[i - 1][k - 1]) % MOD;
        }
      }
    }
  }
  cout << f[N][M];
  return 0;
}
