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