#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 5;
const long long M = 1e9 + 7;
long long mod(long long m) {
  m %= M;
  return (m + M) % M;
}
long long power(long long x, long long y) {
  long long res = 1;
  x = mod(x);
  while (y > 0) {
    if (y & 1) res = mod(res * x);
    y = y >> 1;
    x = mod(x * x);
  }
  return mod(res);
}
long long a[N], b[N], dp[N][N];
long long n, m;
long long solve(long long i, long long j) {
  if (i >= n or j >= m) return 0;
  long long &tmp = dp[i][j];
  if (tmp != -1) return tmp;
  tmp = 0;
  if (a[i] == b[j]) {
    tmp = 1;
    for (long long l = i + 1; l < n; l++) {
      for (long long r = j + 1; r < m; r++) tmp = mod(tmp + solve(l, r));
    }
  }
  return tmp;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  memset(dp, -1, sizeof dp);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++)
      if (a[i] == b[j]) ans = mod(ans + solve(i, j));
  }
  ans = mod(ans + 1);
  cout << ans << endl;
}
