#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<ll, ll>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T add(const T &a, const T &b) {
  return (a + b) % mod;
}
signed main() {
  ll n, m;
  cin >> n >> m;
  vi s(n);
  for (ll i = 0, i_cond = (n); i < i_cond; ++i) cin >> s[i];
  vi t(m);
  for (ll i = 0, i_cond = (m); i < i_cond; ++i) cin >> t[i];
  vvi dp(n + 1, vi(m + 1));
  for (ll i = 0, i_cond = (n + 1); i < i_cond; ++i) dp[i][0] = 1;
  for (ll j = 0, j_cond = (m + 1); j < j_cond; ++j) dp[0][j] = 1;
  for (ll i = 0, i_cond = (n); i < i_cond; ++i)
    for (ll j = 0, j_cond = (m); j < j_cond; ++j) {
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
      if (s[i] != t[j]) dp[i + 1][j + 1] -= dp[i][j];
      dp[i + 1][j + 1] %= mod;
    }
  cout << dp[n][m] << endl;
}
