#include <bits/stdc++.h>
using namespace std;
long long a, b, c, i, j, k, l, m, n, s, x[2040], y[2040], z[2040][2040];
int main() {
  scanf("%lld%lld", &n, &m);
  for (; i++ < n;) scanf("%lld", x + i);
  for (i = 0; i++ < m;) scanf("%lld", y + i);
  for (i = 0; i <= n; i++)
    for (j = 0; j <= m; j++)
      z[i][j] = (i < 1 | j < 1 ? 1
                               : z[i - 1][j] + z[i][j - 1] -
                                     (x[i] == y[j] ? 0 : z[i - 1][j - 1])) %
                1000000007;
  printf("%lld", z[n][m]);
}
