#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;
const llong inf = 1100100100100100ll;
const llong mod = 1e9 + 7;
int main() {
  llong N, M;
  vector<llong> S, T;
  vector<vector<llong> > dp;
  cin >> N >> M;
  S.resize(N + 1);
  T.resize(M + 1);
  for (int i = 1; i <= N; ++i) cin >> S[i];
  for (int i = 1; i <= M; ++i) cin >> T[i];
  dp.resize(N + 1, vector<llong>(M + 1, 0));
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      if (S[i] == T[j])
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + 1) % mod;
      else
        dp[i][j] = max({dp[i - 1][j], dp[i][j - 1],
                        dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]});
    }
  }
  cout << dp[N][M] + 1 << endl;
  return 0;
}
