#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ch = char;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge {
  ll to, cost;
};
struct edge2 {
  ll from, to, cost;
};
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  ll dp[N + 1][M + 1];
  for (ll i = 0; i < N + 1; i++) {
    for (ll j = 0; j < M + 1; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  vector<ll> S(N), T(M);
  for (ll i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (ll i = 0; i < M; i++) {
    cin >> T[i];
  }
  for (ll i = 0; i < N + 1; i++) {
    for (ll j = 0; j < M + 1; j++) {
      if (i * j == 0) {
        dp[i][j] = 1;
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
        if (S[i - 1] == T[j - 1]) {
          dp[i][j] += dp[i - 1][j - 1];
        }
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
}
