#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2050, maxm = 2050, MOD = (1e9) + 7;
int N, M, S[maxn], T[maxm];
long long F[maxn][maxm];
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++) F[i][0] = 1;
  for (int i = 0; i <= M; i++) F[0][i] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      F[i][j] = (F[i - 1][j] + F[i][j - 1] - F[i - 1][j - 1]) % MOD;
      if (S[i] == T[j]) F[i][j] = (F[i][j] + F[i - 1][j - 1]) % MOD;
    }
  }
  printf("%lld\n", F[N][M]);
  return 0;
}
