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