#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
int n, m, a[2005], b[2005], f[2005][2005];
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%d", a + i);
  for (int(i) = (1); (i) <= (m); (i)++) scanf("%d", b + i);
  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 (a[i] == b[j]) f[i][j] = (f[i][j] + f[i - 1][j - 1] + 1) % mod;
    }
  printf("%d", (f[n][m] + 1) % mod);
  return 0;
}
