#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long m, n, ans = 0, sum = 0, p, a[2001], b[2001], dp[2001][2001];
inline long long read() {
  register long long s = 0, t = 0;
  register char ch = getchar();
  while (ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
int main() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long j = 1; j <= m; j++) b[j] = read();
  for (long long i = 1; i <= n; i++) dp[i][0] = 1, dp[0][i] = 1;
  dp[0][0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + mod) % mod;
      if (a[i] == b[j]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
      }
    }
  cout << dp[n][m];
  return 0;
}
