#include <bits/stdc++.h>
int main(void) {
  int i, j, N, M, res, MOD = pow(10, 9) + 7, S[2010], T[2010], dp[2010][2010],
                       total[2010][2010];
  dp[0][0] = 1;
  res = 1;
  scanf("%d %d", &N, &M);
  for (i = 1; i <= N; i++) {
    scanf("%d", &S[i]);
  }
  for (i = 1; i <= M; i++) {
    scanf("%d", &T[i]);
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= M; j++) {
      if (S[i] == T[j]) {
        dp[i][j] = total[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = 0;
      }
      total[i][j] =
          total[i - 1][j] + total[i][j - 1] - total[i - 1][j - 1] + dp[i][j];
      total[i][j] %= MOD;
      res += dp[i][j];
      res %= MOD;
    }
  }
  printf("%d", res % MOD);
  return 0;
}
