#include <bits/stdc++.h>
using namespace std;
long long N, M, S[2020], T[2020];
long long i, j, k, ans;
long long dp[2020][2020];
int main() {
  scanf("%lld%lld", &N, &M);
  for (i = 0; i < N; i++) {
    scanf("%lld", S + i);
  }
  for (i = 0; i < M; i++) {
    scanf("%lld", T + i + 1);
  }
  dp[0][0] = 1;
  for (i = 0; i < N; i++) {
    k = 0;
    for (j = 0; j < M + 1; j++) {
      k = (k + dp[i][j]) % ((long long)1e9 + 7);
      dp[i + 1][j] = dp[i][j];
      if (S[i] != T[j]) continue;
      dp[i + 1][j] += k;
      dp[i + 1][j] % ((long long)1e9 + 7);
    }
  }
  for (i = 0; i < M + 1; i++) {
    ans = (ans + dp[N][i]) % ((long long)1e9 + 7);
  }
  printf("%lld", ans);
  return 0;
}
