#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100 + 2e3, INF = 1e9, mod = 1e9 + 7;
long long n, m;
long long a[maxn], b[maxn], f[maxn][maxn];
void Read() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  return;
}
long long Try(int ia, int ib) {
  long long ans = 0;
  if (ia > n || ib > m) return 0;
  if (f[ia][ib] > 0) return f[ia][ib];
  ans = (ans + Try(ia + 1, ib + 1)) % mod;
  ans = (ans + (a[ia] == b[ib]) * (1 + Try(ia + 1, ib + 1))) % mod;
  for (int i = ia + 1; i <= n; ++i)
    if (a[i] == b[ib]) ans = (ans + 1 + Try(i + 1, ib + 1)) % mod;
  for (int i = ib + 1; i <= m; ++i)
    if (a[ia] == b[i]) ans = (ans + 1 + Try(ia + 1, i + 1)) % mod;
  f[ia][ib] = ans;
  return ans;
}
void Solve() {
  cout << Try(1, 1) + 1;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Read();
  Solve();
  return 0;
}
