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