#include <bits/stdc++.h>
const int MN = 2004, MM = 2004, MOD = 1e9 + 7;
int N, M, S[MN], T[MM];
long long ans = 1, dp[MN][MM];
inline long long exp(long long b, long long e) {
  long long ans = 1;
  while (e) {
    if (e & 1) ans = (ans * b) % MOD;
    b = (b * b) % MOD;
    e >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; ++i) scanf("%d", &S[i]);
  for (int i = 1; i <= M; ++i) scanf("%d", &T[i]);
  for (int i = 0; i <= N; ++i)
    for (int j = 0; j <= M; ++j) dp[i][j] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD;
      if (S[i] == T[j]) {
        ans = (ans + dp[i][j]) % MOD;
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
      }
    }
  }
  printf("%lld\n", dp[N][M]);
}
