#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const long long Mod = 1e9 + 7;
int n, m, s[N], t[N];
long long dp[N][N];
inline int read() {
  int rt = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    rt = (rt << 3) + (rt << 1) + (ch & 15);
    ch = getchar();
  }
  return rt;
}
int main() {
  n = read(), m = read();
  for (register int i = 1; i <= n; ++i) s[i] = read();
  for (register int i = 1; i <= m; ++i) t[i] = read();
  for (register int i = 0; i <= n; ++i) dp[0][i] = dp[i][0] = 1;
  for (register int i = 1; i <= n; ++i)
    for (register int j = 1; j <= m; ++j)
      dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1] -
                   (s[i] == t[j] ? 0 : dp[i - 1][j - 1])) %
                      Mod +
                  Mod) %
                 Mod;
  return not printf("%lld", dp[n][m]);
}
