#include <bits/stdc++.h>
using namespace std;
int read() {
  int xx = 0, ff = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = xx * 10 + ch - '0';
    ch = getchar();
  }
  return xx * ff;
}
long long READ() {
  long long xx = 0, ff = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = xx * 10 + ch - '0';
    ch = getchar();
  }
  return xx * ff;
}
char one() {
  char ch = getchar();
  while (ch == ' ' || ch == '\n') ch = getchar();
  return ch;
}
const int maxn = 2010, MOD = int(1e9) + 7;
int N, M, a[maxn], b[maxn], f[maxn][maxn];
int main() {
  N = read(), M = read();
  for (int i = 1; i <= N; i++) a[i] = read();
  for (int i = 1; i <= M; i++) b[i] = read();
  for (int i = 0; i < maxn; i++) f[i][0] = f[0][i] = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (i + j) {
        f[i][j] =
            ((f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1]) % MOD + MOD) % MOD;
        if (a[i] == b[j]) (f[i][j] += f[i - 1][j - 1]) %= MOD;
      }
  printf("%d\n", f[N][N]);
  return 0;
}
