#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long INFL = 1000000000000000010;
int INF = 1000000000;
long long MOD = 1000000007;
int main(void) {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N), T(M);
  for (long long i = 0; i < N; i++) cin >> S[i];
  for (long long i = 0; i < M; i++) cin >> T[i];
  long long dp[N + 1][M + 1];
  long long sum[N + 1][M + 1];
  memset(sum, 0, sizeof(sum));
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = sum[i][j] + 1;
        dp[i + 1][j + 1] %= MOD;
      } else {
        dp[i + 1][j + 1] = 0;
      }
      sum[i + 1][j + 1] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cout << (sum[N][M] + 1) % MOD << endl;
}
