#include <bits/stdc++.h>
using namespace std;
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
template <class T>
bool chmax(T &former, const T &b) {
  if (former < b) {
    former = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T>
T sqar(T x) {
  return x * x;
}
template <class T>
inline void princ(T x) {
  cout << x << " ";
};
template <class T>
inline void print(T x) {
  cout << x << "\n";
};
template <class T>
inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T>
inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
ll n, m;
Vi a, b;
ll dp[2001][2001];
ll calc(ll aa, ll bb) {
  if (dp[aa][bb] != 0) return dp[aa][bb];
  ll ans = 0;
  if (aa > 0) ans += calc(aa - 1, bb);
  if (bb > 0) ans += calc(aa, bb - 1);
  if (aa > 0 && bb > 0) {
    ans -= calc(aa - 1, bb - 1);
    if (a[aa - 1] == b[bb - 1]) {
      ans += calc(aa - 1, bb - 1);
    }
  }
  ans %= Mod;
  return dp[aa][bb] = ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(30);
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  for (ll i = 0; i < n; i++) cin >> a[i];
  for (ll i = 0; i < m; i++) cin >> b[i];
  for (ll i = 0; i < 2001; i++)
    for (ll j = 0; j < 2001; j++) dp[i][j] = 0;
  dp[0][0] = 1;
  print(calc(n, m));
  return 0;
}
