#include <bits/stdc++.h>
using namespace std;
long long ara[2003][2003], tra[2003][2003], val[2003], tal[2003];
long long mod = 1000000007;
int main() {
  long long n, m, i, j, k, x, y, z, p, q, r, a, b = 1;
  scanf("%lld %lld", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a);
    val[i] = a;
  }
  for (i = 1; i <= m; i++) {
    scanf("%lld", &a);
    tal[i] = a;
  }
  ara[0][0] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      k = 0;
      x = 0;
      y = 0;
      z = 0;
      p = i - 1;
      q = j - 1;
      if (p - 1 >= 0) x = tra[p - 1][q];
      if (q - 1 >= 0) y = tra[p][q - 1];
      if (p - 1 >= 0 && q - 1 >= 0) z = tra[p - 1][q - 1];
      if (val[i] == tal[j]) {
        ara[i][j] = tra[p][q] + 1;
      }
      b = (b + ara[i][j]) % mod;
      tra[i][j] = tra[i - 1][j] + tra[i][j - 1] - tra[i - 1][j - 1] + ara[i][j];
    }
  }
  printf("%lld\n", b);
  return 0;
}
