#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int main() {
  long long N, M;
  cin >> N >> M;
  long long S[N + 1], T[N + 1];
  long long i, j;
  for (i = 1; i <= N; i++) {
    cin >> S[i];
  }
  for (j = 1; j <= M; j++) {
    cin >> T[j];
  }
  long long dp[N + 1][M + 1];
  long long sum[N + 1][M + 1];
  for (i = 0; i <= N; i++) {
    for (j = 0; j <= M; j++) {
      dp[i][j] = 0;
      sum[i][j] = 0;
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= M; j++) {
      if (S[i] == T[j]) {
        dp[i][j] = sum[i - 1][j - 1] + 1;
        dp[i][j] %= MOD;
      } 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] += MOD;
      sum[i][j] %= MOD;
    }
  }
  cout << (sum[N][M] + 1) % MOD << endl;
  system("pause");
  return 0;
}
