#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  long long Si;
  vector<long long> S, T;
  for (int i = 0; i < N; i++) {
    cin >> Si;
    S.push_back(Si);
  }
  for (int i = 0; i < M; i++) {
    cin >> Si;
    T.push_back(Si);
  }
  vector<vector<long long>> sum(N + 1, vector<long long>(M + 1, 1));
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (S[i - 1] == T[j - 1]) {
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1];
      } else {
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      }
      sum[i][j] %= 1000000007;
    }
  }
  cout << sum[N][M] << endl;
  return 0;
}
