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