#include <bits/stdc++.h>
using namespace std;
using Pi = pair<long long, long long>;
using Graph = vector<vector<long long> >;
using WeightGraph = vector<vector<Pi> >;
long long S[2100];
long long T[2100];
long long DP[2100][2100];
signed main() {
  long long N, M;
  cin >> N >> M;
  for (long long i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (long long i = 0; i < M; i++) {
    cin >> T[i];
  }
  memset(DP, 0, sizeof(DP));
  DP[0][0] = 1;
  for (long long i = 0; i <= N; i++) {
    for (long long j = 0; j <= M; j++) {
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
        DP[i][j] += DP[i - 1][j - 1];
      }
      if (i - 1 >= 0) {
        DP[i][j] += DP[i - 1][j];
      }
      if (j - 1 >= 0) {
        DP[i][j] += DP[i][j - 1];
      }
      if (i - 1 >= 0 && j - 1 >= 0) {
        DP[i][j] -= DP[i - 1][j - 1];
      }
      DP[i][j] %= 1000000007;
      ;
    }
  }
  cout << DP[N][M] << endl;
}
