#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T gcd(const T &a, const T &b) {
  return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(const T &a, const T &b) {
  return a / gcd(a, b) * b;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using namespace std;
int main() {
  constexpr ll p = 1000000007;
  ll n, m;
  cin >> n >> m;
  vector<ll> s(n), t(m);
  for (long long i = 0, i_len = (n); i < i_len; i++) cin >> s[i];
  for (long long i = 0, i_len = (m); i < i_len; i++) cin >> t[i];
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
  for (long long i = 0, i_len = (n + 1); i < i_len; i++) dp[i][0] = 1;
  for (long long i = 0, i_len = (m + 1); i < i_len; i++) dp[0][i] = 1;
  for (long long i = (1), i_end = (n); i <= i_end; i++)
    for (long long j = (1), j_end = (m); j <= j_end; j++) {
      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] % p + (p - dp[i - 1][j - 1])) % p;
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1];
        dp[i][j] %= p;
      }
    }
  cout << dp[n][m] << endl;
  cerr << "[DEBUG]\n";
  for (long long i = 0, i_len = (n + 1); i < i_len; i++)
    for (long long j = 0, j_len = (m + 1); j < j_len; j++)
      cerr << dp[i][j] << " \n"[j == m];
}
