#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}
const ll mod = 1e9 + 7;
const ll inf = 1e18;
void vprint(vector<ll> A) {
  ll L = A.size();
  for (ll i = (0); i < (L); ++i) {
    if (i) cout << ' ';
    cout << A[i];
  }
  cout << endl;
}
ll dp[2100][2100];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  for (ll i = (0); i < (N); ++i) {
    cin >> A.at(i);
  }
  vector<ll> B(M);
  for (ll i = (0); i < (M); ++i) {
    cin >> B.at(i);
  }
  for (ll i = (1); i < (N + 1); ++i) {
    for (ll j = (1); j < (M + 1); ++j) {
      if (A[i - 1] == B[j - 1]) {
        dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j];
        dp[i][j] %= mod;
      } else {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
        dp[i][j] %= mod;
      }
    }
  }
  cout << (dp[N][M] + 1) << endl;
  return 0;
}
