#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {-1, 0, 1, 0};
const int INF = 1e9 + 7;
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (y == 0) return x;
  return gcd(y, x % y);
}
void mul(ll a, ll b) { a = a * b % INF; }
double mysqrt(double x) {
  double l = 0, r = x;
  for (int i = 0; i < 64; ++i) {
    double m = (l + r) / 2.0;
    if (m * m < x)
      l = m;
    else
      r = m;
  }
  return l;
}
ll dp[2010][2010];
ll sum[2010][2010];
int main() {
  int n, m;
  cin >> n >> m;
  int s[2010], t[2010];
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < m; ++i) cin >> t[i];
  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = sum[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = 0;
      }
      sum[i + 1][j + 1] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= INF;
    }
  }
  ll ans = 1;
  for (int i = 0; i < n + 1; ++i) {
    for (int j = 0; j < m + 1; ++j) {
      ans += dp[i][j];
      ans %= INF;
    }
  }
  cout << ans << endl;
  return 0;
}
