#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main() {
  init();
  ll N, M;
  cin >> N >> M;
  vl S(N), T(M);
  for (ll i = 0; i < (N); i++) cin >> S[i];
  for (ll i = 0; i < (M); i++) cin >> T[i];
  vvc<ll> dp(N + 1, vc<ll>(M + 1, 0));
  dp[0][0] = 0;
  for (ll i = 0; i < (N); i++)
    for (ll j = 0; j < (M); j++) {
      if (S[i] == T[j])
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] + 1) % MOD;
      else
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % MOD;
    }
  cout << dp[N][M] + 1 << endl;
}
