#include <bits/stdc++.h>
using ll = long long;
constexpr ll mod = 1000000007;
ll N, M;
ll S[2010], T[2010];
ll dp[2010][2010], sum[2010][2010];
int main() {
  scanf("%lld%lld", &N, &M);
  for (int i = (0); i < (N); ++i) scanf("%lld", S + i);
  for (int i = (0); i < (M); ++i) scanf("%lld", T + i);
  for (int i = (0); i < (N); ++i)
    for (int j = (0); j < (M); ++j) {
      if (S[i] == T[j]) dp[i + 1][j + 1] = (sum[i][j] + 1) % mod;
      sum[i + 1][j + 1] =
          (((sum[i + 1][j] + sum[i][j + 1]) % mod - sum[i][j]) % mod +
           dp[i + 1][j + 1]) %
          mod;
    }
  printf("%lld\n", (sum[N][M] + 1) % mod);
  return 0;
}
