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