#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long SZ = 107;
const long long N = 2e3 + 7;
const long long inf = 1e17;
long long pwr(long long x, long long y) {
  long long r = 1LL;
  while (y) {
    if (y & 1) r = (r * x) % MOD;
    y >>= 1;
    x = (x * x) % MOD;
  }
  return r % MOD;
}
long long inv(long long x) { return pow(x, MOD - 2); }
long long dp[N][N], n, m, a[N], b[N];
long long solve(long long idx1, long long idx2) {
  if (idx1 > n or idx2 > m) return 0;
  long long ans = dp[idx1][idx2];
  if (ans != -1) return ans;
  ans = 0;
  if (a[idx1] == b[idx2])
    ans += 1 + solve(idx1 + 1, idx2) + solve(idx1, idx2 + 1);
  else
    ans += solve(idx1 + 1, idx2) + solve(idx1, idx2 + 1) -
           solve(idx1 + 1, idx2 + 1);
  ans %= MOD;
  return dp[idx1][idx2] = ans;
}
void solve() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= m; i++) cin >> b[i];
  memset(dp, -1, sizeof(dp));
  long long ans = 1 + solve(1, 1);
  ans %= MOD;
  cout << ans;
}
signed main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
