#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> 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>> sum(N + 1, vector<long long>(M + 1, 0));
  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] + 1;
      } else {
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      }
      sum[i][j] %= MOD;
    }
  }
  cout << (sum[N][M] + 1) % MOD << endl;
  return 0;
}
